Commit Graph

46 Commits

Author SHA1 Message Date
Thomas O'Dowd 62ab2cfd17 Fix race condition between writing and prompting.
Introduce a new operation.isPrompting field which is true from when a
prompt has been written until data is returned to the caller.
When Write is called on the wrapWriter to write to stdout or stderr,
check if we are currently prompting the user for input and if so
clean up the prompt and write the data before redrawing the
prompt at its new location after the written data.

Previously terminal.IsReading() was used for this, but this had various
race conditions and it was not correct to check this field to make
prompt and buffer redrawing decisions. In turn, I removed all the
isReading code also. The old isReading() check was actually checking
if the terminal goroutine was actively waiting for more input.
2023-03-04 18:35:07 +09:00
Thomas O'Dowd d9af567781 Various screen redraw fixes for wide characters, narrow screens etc.
- Don't overwrite existing text on same line as the prompt
- Don't refresh screen when simply appending characters to buffer
- Don't refresh screen unnessarily when pressing enter key
- Handle prompts longer than screen width.
- Fix wide characters in prompt
- Fix screen edge issue when next character is wide.
- Fix screen edge issue for masked characters
- Fix narrow masked characteter, masking wide input
- Fix wide masked character, masking narrow input
- Reworked backspacesequence for index to use same algorithm as used
  for lineedge and reduce the control sequences to 2.
- Reworked cleanup to incorporate initial cursor column position
  and avoid overwriting existing text as well as simplifying the
  control sequences used.
- Fixed double width character detection and updated unit tests
- Handle emoji in text or prompts.
- Implement windows ANSI absolute horizonal position ansi code.
- Get windows cursor position directly and don't send ansi DSR code
- Don't write out empty mask runes
- Cleanup - removed unused hadCLean variable
2023-02-28 11:00:57 +09:00
Thomas O'Dowd 8e4bd417b9
Handle keypad mode cursor key escape sequences. (#203)
Normally the terminal uses CSI escape sequences when the UP, DOWN,
LEFT, RIGHT and HOME, END keys are pressed. These look like the
following ESC [ A etc, where ESC [ is the CSI sequence.

xterm and other terminals however can generate an alternative
escape sequence called SS3 if in the application keypad mode.
This sequence is ESC O A etc.

Bash readline understands both modes so nowadays you rarely
see OA being printed when you press the up arrow while the terminal
is using the keypad mode. readline currently does not understand
these sequences.

To test this fix, I used an xterm and put it in keypad mode
using the command "tput smkx". Then I started the readline-demo
and tried using arrow keys. Without this fix, OA is printed when
I press up. With this fix, readline fetches the previous command
as per regular mode. After testing you can escape back to
regular mode using "tput rmkx".
2022-05-20 21:29:21 +08:00
ChenYe 80e2d1961b
restore term when receive signal (#200)
* restore term when receive signal

add `CaptureExitSignal` to capture exit signals and exit gracefull(disabled by default)

* update deps
2022-04-24 21:25:55 +08:00
Sagar Mittal 9f56defe66 Add barebones support for yank/paste (#120) 2017-10-01 22:57:50 -05:00
Gereon Frey 8a1389155f Solaris support (#110)
* Add support for solaris

* Change state to handle system dependent termios type.
* Move syscalls to get and set termios to functions in files only built
  for respective platforms.
* Create `term_unix.go` go file built on all supported unices except
  solaris with types and functions valid for all of them.
* Change `MakeRaw` to set VMIN and VTIME to default values.

Fixes #95.

* Fix error handling

Doing the string comparison could be improved, but at least we should
return an error, if it is not "errno 0".
2017-03-13 07:57:45 +08:00
chzyer bc5c91eb5b remove unused files 2016-09-03 11:26:39 +08:00
chzyer 27fdf0b285 Fix: a backup plan when can't get size of terminal (#71)
* fix (0,0) size

* fix
2016-08-31 23:51:28 +08:00
chzyer d478c186fd Fix #62: move dependent package "terminal" to "term" (#65) 2016-07-22 00:31:42 +08:00
chzyer 683bf8ff7c Fix #59 , support HOME/END for <Esc>OH/F 2016-06-21 17:53:53 +08:00
chzyer 3ea5940c39 support suspend process (#48)
* support suspend process

* fix suspend in windows

* add comments
2016-04-17 21:05:00 +08:00
chzyer 6cc043de37 Fix #43 , remove sub-package for gopkg compatiblity 2016-04-05 09:55:46 +08:00
chzyer e5e328dcc7 remove SplitByMultiLine 2016-03-31 00:15:33 +08:00
chzyer bb5b4af6e7 fix wordbreak to add number 2016-03-25 17:07:55 +08:00
chzyer b57eccfd02 add remote mode 2016-03-13 18:32:48 +08:00
Cheney 4ae9d7e0fd fix multiline 2016-03-05 15:45:42 +08:00
Cheney 867002449c refactory 2016-03-05 15:45:42 +08:00
Cheney 15e7be4ac2 add new interface and fixed crash if stdout isn't a tty 2016-02-18 11:25:41 +08:00
Cheney 21acaf90fd fixed crash if stdin is not a tty (pipe) 2016-02-17 14:08:55 +08:00
Cheney d59da2cf77 refactor excapeExKey 2015-10-28 09:02:52 +08:00
Pristáš Michal bcc2f0762c reader nil check in escapeExKey 2015-10-26 09:45:11 +01:00
Pristáš Michal 30303e5637 reader nil check in escapeExKey 2015-10-26 09:43:34 +01:00
Pristáš Michal 391c225c0b delete redundancy char check moved to escapeExKey method 2015-10-26 09:41:48 +01:00
Pristáš Michal de44b28597 cleanup 2015-10-23 13:19:36 +02:00
Pristáš Michal 1c411ac48c changes completed 2015-10-23 13:16:45 +02:00
Cheney 55809b401d add runes package 2015-10-04 21:56:34 +08:00
Cheney 79d1bf27b4 add simple vim mode 2015-10-01 22:44:43 +08:00
Cheney 6eb29567f6 support ANSI escape sequence for windows 2015-09-29 21:01:17 +08:00
Cheney c814ccae9a fix build in windows 2015-09-28 09:46:33 +08:00
Cheney 8dc3117d78 add todo: support windows 2015-09-27 11:41:05 +08:00
Cheney 593678baa5 refactor 2015-09-27 10:50:14 +08:00
Cheney d07044cdb6 add prefix completer 2015-09-26 00:31:09 +08:00
Cheney 04f86e9c53 add auto complete 2015-09-25 22:56:00 +08:00
Cheney f179b24304 support double-width-char & colorful prompt 2015-09-25 12:45:39 +08:00
Cheney a904b314b8 kickoff ioloop only needs, solved #1 2015-09-25 00:16:49 +08:00
Cheney a659448259 update example 2015-09-23 14:52:45 +08:00
Cheney bfdaae1594 fix typo 2015-09-23 13:03:13 +08:00
Cheney 9848c61567 fix word breaker 2015-09-23 11:59:39 +08:00
Cheney 4ab9a96399 refactor 2015-09-23 11:46:56 +08:00
Cheney a7f498f047 fix fwd/bck search 2015-09-23 11:10:36 +08:00
Cheney 3b1cf6b8fb add fwd/bck search 2015-09-22 23:01:15 +08:00
Cheney 9c65cb7ccf fix runebuffer refresh 2015-09-21 22:27:40 +08:00
Cheney e878807b59 add support for arrow/up/down/left/right 2015-09-21 21:14:05 +08:00
Cheney 772978399e improve history 2015-09-21 21:00:48 +08:00
Cheney 6642cc6506 support history 2015-09-21 13:14:10 +08:00
Cheney 740e90a464 init commit 2015-09-20 23:14:29 +08:00