From d6c6bcc9f3157d87081db900c7f3903dbaa1e9d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Thu, 11 Feb 2016 16:46:28 +0200 Subject: cmd/geth: update monitor to new termui code --- cmd/geth/monitorcmd.go | 47 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 25 deletions(-) (limited to 'cmd/geth') diff --git a/cmd/geth/monitorcmd.go b/cmd/geth/monitorcmd.go index 4d56f2289..120f6b9f4 100644 --- a/cmd/geth/monitorcmd.go +++ b/cmd/geth/monitorcmd.go @@ -105,8 +105,6 @@ func monitor(ctx *cli.Context) { } defer termui.Close() - termui.UseTheme("helloworld") - rows := len(monitored) if max := ctx.Int(monitorCommandRowsFlag.Name); rows > max { rows = max @@ -117,7 +115,7 @@ func monitor(ctx *cli.Context) { } // Create each individual data chart footer := termui.NewPar("") - footer.HasBorder = true + footer.Block.Border = true footer.Height = 3 charts := make([]*termui.LineChart, len(monitored)) @@ -135,28 +133,27 @@ func monitor(ctx *cli.Context) { termui.Render(termui.Body) // Watch for various system events, and periodically refresh the charts - refresh := time.Tick(time.Duration(ctx.Int(monitorCommandRefreshFlag.Name)) * time.Second) - for { - select { - case event := <-termui.EventCh(): - if event.Type == termui.EventKey && event.Key == termui.KeyCtrlC { - return - } - if event.Type == termui.EventResize { - termui.Body.Width = termui.TermWidth() - for _, chart := range charts { - chart.Height = (termui.TermHeight() - footer.Height) / rows - } - termui.Body.Align() - termui.Render(termui.Body) - } - case <-refresh: + termui.Handle("/sys/kbd/C-c", func(termui.Event) { + termui.StopLoop() + }) + termui.Handle("/sys/wnd/resize", func(termui.Event) { + termui.Body.Width = termui.TermWidth() + for _, chart := range charts { + chart.Height = (termui.TermHeight() - footer.Height) / rows + } + termui.Body.Align() + termui.Render(termui.Body) + }) + go func() { + tick := time.NewTicker(time.Duration(ctx.Int(monitorCommandRefreshFlag.Name)) * time.Second) + for range tick.C { if refreshCharts(client, monitored, data, units, charts, ctx, footer) { termui.Body.Align() } termui.Render(termui.Body) } - } + }() + termui.Loop() } // retrieveMetrics contacts the attached geth node and retrieves the entire set @@ -328,9 +325,9 @@ func updateChart(metric string, data []float64, base *int, chart *termui.LineCha if strings.Contains(metric, "/Percentiles/") || strings.Contains(metric, "/pauses/") || strings.Contains(metric, "/time/") { units = timeUnits } - chart.Border.Label = metric + chart.BorderLabel = metric if len(units[unit]) > 0 { - chart.Border.Label += " [" + units[unit] + "]" + chart.BorderLabel += " [" + units[unit] + "]" } chart.LineColor = colors[unit] | termui.AttrBold if err != nil { @@ -350,8 +347,8 @@ func createChart(height int) *termui.LineChart { chart.AxesColor = termui.ColorWhite chart.PaddingBottom = -2 - chart.Border.LabelFgColor = chart.Border.FgColor | termui.AttrBold - chart.Border.FgColor = chart.Border.BgColor + chart.BorderLabelFg = chart.BorderFg | termui.AttrBold + chart.BorderFg = chart.BorderBg return chart } @@ -361,7 +358,7 @@ func updateFooter(ctx *cli.Context, err error, footer *termui.Par) { // Generate the basic footer refresh := time.Duration(ctx.Int(monitorCommandRefreshFlag.Name)) * time.Second footer.Text = fmt.Sprintf("Press Ctrl+C to quit. Refresh interval: %v.", refresh) - footer.TextFgColor = termui.Theme().ParTextFg | termui.AttrBold + footer.TextFgColor = termui.ThemeAttr("par.fg") | termui.AttrBold // Append any encountered errors if err != nil { -- cgit v1.2.3 From 4063d30b5e8c0a47d28c8a84169ff3c61512c4c9 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Fri, 12 Feb 2016 02:20:18 +0100 Subject: cmd/geth: gofmt js.go and rename ethereum.js to web3.js Fixing the filename matters now because it will actually show up in JS backtraces. --- cmd/geth/js.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'cmd/geth') diff --git a/cmd/geth/js.go b/cmd/geth/js.go index 3d0251f08..ebbf55e50 100644 --- a/cmd/geth/js.go +++ b/cmd/geth/js.go @@ -91,8 +91,8 @@ func keywordCompleter(jsre *jsre, line string) []string { objRef := "this" prefix := line if len(parts) > 1 { - objRef = strings.Join(parts[0:len(parts) - 1], ".") - prefix = parts[len(parts) - 1] + objRef = strings.Join(parts[0:len(parts)-1], ".") + prefix = parts[len(parts)-1] } result, _ := jsre.re.Run(fmt.Sprintf(autoCompleteStatement, objRef)) @@ -103,7 +103,7 @@ func keywordCompleter(jsre *jsre, line string) []string { if objRef == "this" { results = append(results, fmt.Sprintf("%s", k)) } else { - results = append(results, fmt.Sprintf("%s.%s", strings.Join(parts[:len(parts) - 1], "."), k)) + results = append(results, fmt.Sprintf("%s.%s", strings.Join(parts[:len(parts)-1], "."), k)) } } } @@ -112,7 +112,7 @@ func keywordCompleter(jsre *jsre, line string) []string { // e.g. web3 append dot since its an object isObj, _ := jsre.re.Run(fmt.Sprintf("typeof(%s) === 'object'", line)) if isObject, _ := isObj.ToBoolean(); isObject { - results = append(results, line + ".") + results = append(results, line+".") } sort.Strings(results) @@ -131,7 +131,7 @@ func apiWordCompleterWithContext(jsre *jsre) liner.WordCompleter { if line[i] == '.' || (line[i] >= 'a' && line[i] <= 'z') || (line[i] >= 'A' && line[i] <= 'Z') { continue } - if i >= 3 && line[i] == '3' && line[i - 3] == 'w' && line[i - 2] == 'e' && line[i - 1] == 'b' { + if i >= 3 && line[i] == '3' && line[i-3] == 'w' && line[i-2] == 'e' && line[i-1] == 'b' { continue } i += 1 @@ -280,7 +280,7 @@ func (js *jsre) apiBindings() error { utils.Fatalf("Error loading bignumber.js: %v", err) } - err = js.re.Compile("ethereum.js", re.Web3_JS) + err = js.re.Compile("web3.js", re.Web3_JS) if err != nil { utils.Fatalf("Error loading web3.js: %v", err) } -- cgit v1.2.3 From 2abf1a36b9e7941a53622c0b65ef23a4f03418af Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Fri, 12 Feb 2016 02:41:29 +0100 Subject: cmd/geth: enable multi-line mode This was requested by some users earlier but liner didn't support it at the time. It does now. --- cmd/geth/js.go | 1 + 1 file changed, 1 insertion(+) (limited to 'cmd/geth') diff --git a/cmd/geth/js.go b/cmd/geth/js.go index ebbf55e50..62a3a69bc 100644 --- a/cmd/geth/js.go +++ b/cmd/geth/js.go @@ -168,6 +168,7 @@ func newLightweightJSRE(docRoot string, client rpc.Client, datadir string, inter js.loadAutoCompletion() lr.SetWordCompleter(apiWordCompleterWithContext(js)) lr.SetTabCompletionStyle(liner.TabPrints) + lr.SetMultiLineMode(true) js.prompter = lr js.atexit = func() { js.withHistory(datadir, func(hist *os.File) { hist.Truncate(0); lr.WriteHistory(hist) }) -- cgit v1.2.3 From ae5bc89cad98a4fd3176502b66678d768f2fd15f Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Mon, 15 Feb 2016 14:56:26 +0100 Subject: cmd/geth, jsre: improve auto-completion --- cmd/geth/js.go | 69 +++++----------------------------------------------------- 1 file changed, 5 insertions(+), 64 deletions(-) (limited to 'cmd/geth') diff --git a/cmd/geth/js.go b/cmd/geth/js.go index 62a3a69bc..e7e28b24b 100644 --- a/cmd/geth/js.go +++ b/cmd/geth/js.go @@ -80,51 +80,11 @@ type jsre struct { prompter } -var ( - loadedModulesMethods map[string][]string - autoCompleteStatement = "function _autocomplete(obj) {var results = []; for (var e in obj) { results.push(e); }; return results; }; _autocomplete(%s)" -) - -func keywordCompleter(jsre *jsre, line string) []string { - var results []string - parts := strings.Split(line, ".") - objRef := "this" - prefix := line - if len(parts) > 1 { - objRef = strings.Join(parts[0:len(parts)-1], ".") - prefix = parts[len(parts)-1] - } - - result, _ := jsre.re.Run(fmt.Sprintf(autoCompleteStatement, objRef)) - raw, _ := result.Export() - if keys, ok := raw.([]interface{}); ok { - for _, k := range keys { - if strings.HasPrefix(fmt.Sprintf("%s", k), prefix) { - if objRef == "this" { - results = append(results, fmt.Sprintf("%s", k)) - } else { - results = append(results, fmt.Sprintf("%s.%s", strings.Join(parts[:len(parts)-1], "."), k)) - } - } - } - } - - // e.g. web3 append dot since its an object - isObj, _ := jsre.re.Run(fmt.Sprintf("typeof(%s) === 'object'", line)) - if isObject, _ := isObj.ToBoolean(); isObject { - results = append(results, line+".") - } - - sort.Strings(results) - return results -} - -func apiWordCompleterWithContext(jsre *jsre) liner.WordCompleter { - completer := func(line string, pos int) (head string, completions []string, tail string) { +func makeCompleter(re *jsre) liner.WordCompleter { + return func(line string, pos int) (head string, completions []string, tail string) { if len(line) == 0 || pos == 0 { return "", nil, "" } - // chuck data to relevant part for autocompletion, e.g. in case of nested lines eth.getBalance(eth.coinb i := 0 for i = pos - 1; i > 0; i-- { @@ -137,16 +97,8 @@ func apiWordCompleterWithContext(jsre *jsre) liner.WordCompleter { i += 1 break } - - begin := line[:i] - keyword := line[i:pos] - end := line[pos:] - - completionWords := keywordCompleter(jsre, keyword) - return begin, completionWords, end + return line[:i], re.re.CompleteKeywords(line[i:pos]), line[pos:] } - - return completer } func newLightweightJSRE(docRoot string, client rpc.Client, datadir string, interactive bool) *jsre { @@ -165,8 +117,7 @@ func newLightweightJSRE(docRoot string, client rpc.Client, datadir string, inter lr := liner.NewLiner() js.withHistory(datadir, func(hist *os.File) { lr.ReadHistory(hist) }) lr.SetCtrlCAborts(true) - js.loadAutoCompletion() - lr.SetWordCompleter(apiWordCompleterWithContext(js)) + lr.SetWordCompleter(makeCompleter(js)) lr.SetTabCompletionStyle(liner.TabPrints) lr.SetMultiLineMode(true) js.prompter = lr @@ -197,8 +148,7 @@ func newJSRE(stack *node.Node, docRoot, corsDomain string, client rpc.Client, in lr := liner.NewLiner() js.withHistory(stack.DataDir(), func(hist *os.File) { lr.ReadHistory(hist) }) lr.SetCtrlCAborts(true) - js.loadAutoCompletion() - lr.SetWordCompleter(apiWordCompleterWithContext(js)) + lr.SetWordCompleter(makeCompleter(js)) lr.SetTabCompletionStyle(liner.TabPrints) js.prompter = lr js.atexit = func() { @@ -210,15 +160,6 @@ func newJSRE(stack *node.Node, docRoot, corsDomain string, client rpc.Client, in return js } -func (self *jsre) loadAutoCompletion() { - if modules, err := self.supportedApis(); err == nil { - loadedModulesMethods = make(map[string][]string) - for module, _ := range modules { - loadedModulesMethods[module] = rpc.AutoCompletion[module] - } - } -} - func (self *jsre) batch(statement string) { err := self.re.EvalAndPrettyPrint(statement) -- cgit v1.2.3