mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-11-27 23:11:20 +08:00
Remove edit:-dump-buf.
This used to be used for taking ttyshots but is now obsolete.
This commit is contained in:
parent
2f21892e0c
commit
27e2df9394
|
@ -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("</span>")
|
||||
}
|
||||
if c.Style == "" {
|
||||
openedSpan = false
|
||||
} else {
|
||||
var classes []string
|
||||
for _, c := range strings.Split(c.Style, ";") {
|
||||
classes = append(classes, "sgr-"+c)
|
||||
}
|
||||
fmt.Fprintf(&sb,
|
||||
`<span class="%s">`, strings.Join(classes, " "))
|
||||
openedSpan = true
|
||||
}
|
||||
style = c.Style
|
||||
}
|
||||
fmt.Fprintf(&sb, "%s", html.EscapeString(c.Text))
|
||||
}
|
||||
if openedSpan {
|
||||
sb.WriteString("</span>")
|
||||
}
|
||||
sb.WriteString("\n")
|
||||
}
|
||||
return sb.String()
|
||||
}
|
|
@ -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(
|
||||
`<span class="sgr-31">abc</span>` + "\n",
|
||||
),
|
||||
// Mixing plain and styled texts.
|
||||
Args(
|
||||
bb().
|
||||
WriteStringSGR("abc", "31").
|
||||
Write(" def ").
|
||||
WriteStringSGR("xyz", "1").
|
||||
Buffer(),
|
||||
).Rets(
|
||||
`<span class="sgr-31">abc</span> def <span class="sgr-1">xyz</span>` + "\n",
|
||||
),
|
||||
// Multiple lines.
|
||||
Args(
|
||||
bb().
|
||||
WriteStringSGR("abc", "31").
|
||||
Newline().Write("def").
|
||||
Newline().WriteStringSGR("xyz", "1").
|
||||
Buffer(),
|
||||
).Rets(
|
||||
`<span class="sgr-31">abc</span>` + "\n" +
|
||||
`def` + "\n" +
|
||||
`<span class="sgr-1">xyz</span>` + "\n",
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
func bb() *term.BufferBuilder { return term.NewBufferBuilder(20) }
|
|
@ -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) },
|
||||
})
|
||||
|
|
|
@ -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",
|
||||
`~> <span class="sgr-32">echo</span>`+"\n")
|
||||
}
|
||||
|
||||
func TestInsertRaw(t *testing.T) {
|
||||
f := setup(t)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user