From 27e2df9394063e1941a905ba3cd4cc7fd8b4acd0 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Sun, 11 Sep 2022 15:33:59 +0100 Subject: [PATCH] Remove edit:-dump-buf. This used to be used for taking ttyshots but is now obsolete. --- pkg/edit/buf_to_html.go | 44 ------------------------------- pkg/edit/buf_to_html_test.go | 51 ------------------------------------ pkg/edit/builtins.go | 20 -------------- pkg/edit/builtins_test.go | 16 ----------- pkg/edit/testutils_test.go | 7 ++++- 5 files changed, 6 insertions(+), 132 deletions(-) delete mode 100644 pkg/edit/buf_to_html.go delete mode 100644 pkg/edit/buf_to_html_test.go diff --git a/pkg/edit/buf_to_html.go b/pkg/edit/buf_to_html.go deleted file mode 100644 index 167b9d31..00000000 --- a/pkg/edit/buf_to_html.go +++ /dev/null @@ -1,44 +0,0 @@ -package edit - -import ( - "fmt" - "html" - "strings" - - "src.elv.sh/pkg/cli/term" -) - -// TODO(xiaq): Move this into the ui package. - -func bufToHTML(b *term.Buffer) string { - var sb strings.Builder - for _, line := range b.Lines { - style := "" - openedSpan := false - for _, c := range line { - if c.Style != style { - if openedSpan { - sb.WriteString("") - } - if c.Style == "" { - openedSpan = false - } else { - var classes []string - for _, c := range strings.Split(c.Style, ";") { - classes = append(classes, "sgr-"+c) - } - fmt.Fprintf(&sb, - ``, strings.Join(classes, " ")) - openedSpan = true - } - style = c.Style - } - fmt.Fprintf(&sb, "%s", html.EscapeString(c.Text)) - } - if openedSpan { - sb.WriteString("") - } - sb.WriteString("\n") - } - return sb.String() -} diff --git a/pkg/edit/buf_to_html_test.go b/pkg/edit/buf_to_html_test.go deleted file mode 100644 index e08c4f9f..00000000 --- a/pkg/edit/buf_to_html_test.go +++ /dev/null @@ -1,51 +0,0 @@ -package edit - -import ( - "testing" - - "src.elv.sh/pkg/cli/term" - "src.elv.sh/pkg/tt" -) - -var Args = tt.Args - -func TestBufToHTML(t *testing.T) { - tt.Test(t, tt.Fn("bufToHTML", bufToHTML), tt.Table{ - // Just plain text. - Args( - bb().Write("abc").Buffer(), - ).Rets( - `abc` + "\n", - ), - // Just styled text. - Args( - bb().WriteStringSGR("abc", "31").Buffer(), - ).Rets( - `abc` + "\n", - ), - // Mixing plain and styled texts. - Args( - bb(). - WriteStringSGR("abc", "31"). - Write(" def "). - WriteStringSGR("xyz", "1"). - Buffer(), - ).Rets( - `abc def xyz` + "\n", - ), - // Multiple lines. - Args( - bb(). - WriteStringSGR("abc", "31"). - Newline().Write("def"). - Newline().WriteStringSGR("xyz", "1"). - Buffer(), - ).Rets( - `abc` + "\n" + - `def` + "\n" + - `xyz` + "\n", - ), - }) -} - -func bb() *term.BufferBuilder { return term.NewBufferBuilder(20) } diff --git a/pkg/edit/builtins.go b/pkg/edit/builtins.go index 4ef1adde..65450e25 100644 --- a/pkg/edit/builtins.go +++ b/pkg/edit/builtins.go @@ -23,25 +23,6 @@ import ( // // Converts a normal map into a binding map. -//elvdoc:fn -dump-buf -// -// ```elvish -// edit:-dump-buf -// ``` -// -// Dumps the current UI buffer as HTML. This command is used to generate -// "ttyshots" on the [website](https://elv.sh). -// -// Example: -// -// ```elvish-transcript -// set edit:global-binding[Ctrl-X] = { print (edit:-dump-buf) > ~/a.html } -// ``` - -func dumpBuf(tty cli.TTY) string { - return bufToHTML(tty.Buffer()) -} - //elvdoc:fn close-mode // // ```elvish @@ -273,7 +254,6 @@ func wordify(fm *eval.Frame, code string) error { func initTTYBuiltins(app cli.App, tty cli.TTY, nb eval.NsBuilder) { nb.AddGoFns(map[string]any{ - "-dump-buf": func() string { return dumpBuf(tty) }, "insert-raw": func() { insertRaw(app, tty) }, "clear": func() { clear(app, tty) }, }) diff --git a/pkg/edit/builtins_test.go b/pkg/edit/builtins_test.go index e5e5d83b..beb055bd 100644 --- a/pkg/edit/builtins_test.go +++ b/pkg/edit/builtins_test.go @@ -36,22 +36,6 @@ func TestCloseMode(t *testing.T) { } } -func TestDumpBuf(t *testing.T) { - f := setup(t) - - feedInput(f.TTYCtrl, "echo") - // Wait until the buffer we want has shown up. - f.TestTTY(t, - "~> echo", Styles, - " vvvv", term.DotHere, - ) - - evals(f.Evaler, `var html = (edit:-dump-buf)`) - testGlobal(t, f.Evaler, - "html", - `~> echo`+"\n") -} - func TestInsertRaw(t *testing.T) { f := setup(t) diff --git a/pkg/edit/testutils_test.go b/pkg/edit/testutils_test.go index 9da6a700..aa96951a 100644 --- a/pkg/edit/testutils_test.go +++ b/pkg/edit/testutils_test.go @@ -16,9 +16,14 @@ import ( "src.elv.sh/pkg/store" "src.elv.sh/pkg/store/storedefs" "src.elv.sh/pkg/testutil" + "src.elv.sh/pkg/tt" ) -var Styles = clitest.Styles +// Aliases. +var ( + Args = tt.Args + Styles = clitest.Styles +) type fixture struct { Editor *Editor