Skip to content

Commit 1af8717

Browse files
authored
Merge pull request #7 from knz/20230205-paste
New 'paste' command.
2 parents a0e01fe + 89bb2cd commit 1af8717

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ Under `run`, the following input commands are supported:
217217

218218
For example: `key ctrl+c`
219219

220+
- `paste "<text>"`: paste the text as a single key event.
221+
The text can contain Go escape sequences.
222+
223+
For example: `paste "hello\nworld"`
224+
220225
- `resize <W> <H>`: produce a `tea.WindowSizeMsg` with the specified size.
221226

222227
You can also add support for your own input commands by passing an
@@ -386,4 +391,4 @@ If you have any questions or comments:
386391

387392
- for bug fixes, feature requests, etc., [file an issue]()
388393
- for questions, suggestions, etc. you can come chat on the [Charm
389-
Slack](https://charm.sh/slack/).
394+
Discord](https://charm.sh/chat/).

driver.go

+8
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,14 @@ func (d *driver) ApplyTextCommand(t TB, cmd string, args ...string) tea.Cmd {
461461
d.typeIn(args, false)
462462
d.addMsg(tea.KeyMsg(tea.Key{Type: tea.KeyEnter}))
463463

464+
case "paste":
465+
d.assertArgc(t, args, 1)
466+
s, err := strconv.Unquote(args[0])
467+
if err != nil {
468+
t.Fatalf("%s: paste argment error: %v", d.pos, err)
469+
}
470+
d.addMsg(tea.KeyMsg(tea.Key{Type: tea.KeyRunes, Runes: []rune(s)}))
471+
464472
default:
465473
if d.upd != nil {
466474
t.Logf("%s: applying command %q via model updater", d.pos, cmd)

testdata/simple

+21
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,27 @@ TEA PRINT: {MODEL UPDATE}
7373
-- view:
7474
MODEL VIEW🛇
7575

76+
run trace=on
77+
paste "ab\ncd"
78+
----
79+
-- trace: before "paste \"ab\\ncd\""
80+
-- trace: after "paste"
81+
-- view:
82+
MODEL VIEW🛇
83+
-- trace: before finish
84+
-- view:
85+
MODEL VIEW🛇
86+
-- trace: processing 1 messages
87+
-- trace: msg tea.KeyMsg{Type:-1, Runes:[]int32{97, 98, 10, 99, 100}, Alt:false}
88+
-- trace: processing 1 cmds
89+
-- trace: translated cmd: tea.printLineMessage
90+
-- trace: processing 1 messages
91+
-- trace: msg tea.printLineMessage{messageBody:"MODEL UPDATE"}
92+
TEA PRINT: {MODEL UPDATE}
93+
-- trace: at end
94+
-- view:
95+
MODEL VIEW🛇
96+
7697
run trace=on
7798
type ab
7899
type cd

0 commit comments

Comments
 (0)