Commit Graph

53 Commits

Author SHA1 Message Date
Thomas O'Dowd c30c5a000a Fix terminal resize race conditions
The runebuf, search and complete data structures all maintain their
own cache of the terminal width and height. When the terminal is
resized, a signal is sent to a go routine which calls a function
that sets the new width and height to each data structure instance.
However, this races with the main thread reading the sizes.

Instead of introducing more locks, it makes sense that the terminal
itself caches it's width and height and the other structures just
get it as necessary. This removes all the racing.

As part of this change, search, complete and runebuf constructor
changes to no longer require the initial sizes. Also each structure
needs a reference to the Terminal so they can get the width/height.
As the io.Writer parameter is actually the terminal anyway, the
simpliest option was just to change the type from the io.Writer to
Terminal. I don't believe that anyone would be calling these
functions directly so the signature changes should be ok. I also
removed the no longer used OnWidthChange() and OnSizeChange()
functions from these three structures.
2023-03-05 12:21:35 +09:00
Thomas O'Dowd 5346085511 A Pager to list completion candidates if they don't fit on one page.
Main Features:
- If there are too many candidates returned by the completer,
  completemode and completeselectmode did not work properly.
  Similar to the bash completion pager, list candidates and
  offer "--More--" on the end of each page. User can select
  " ", "y" or "Y" to keep listing or "q", "Q", "n", "N" to
  stop listing. When paging completes, we also exit out of
  completion mode.
- Added aggregate completion when entering completeselectmode
  where the candiddates dwindle down sharing a larger common
  prefix. This makes typing a little faster than having to
  select. More bash-like behaviour.

Other Fixes:
- Fix various crashes where candidates are too wide for the
  width of the screen and causes division by zero.
- Fix crash with wide (Asian characters) in completion.
- Streamline redrawing as CompleteRefresh was called too
  often.
- Fix crashes around ctrl-a and ctrl-b in select mode when
  candidates don't fit on a line
- Fix prev/next candidates in select mode when candidates
  don't fit on a line
- Fix crash when ctrl-k was pressed in select mode. This
  caused us to exitselectmode which cleaned up all the data
  but left us in complete mode such that if CompleteRefresh
  was callled directly, the data was not initialized.
- Fix complete and select mode redraw issues when candidates
  did not fit on one line.
- Fix cursor position issues after CompleteRefresh especially
  if the prompt and buffer also went over 1 line.
- Fix redraw issue where exiting completion mode using
  certain key presses leaves candidates on the screen.

Fixes for Windows:
- Use window size for visible height/width instead of buffer size
- Adjust for Window's EOL behaviour.

Notes:
- Added Height info to different structures as the decision to
  page or not required height information.
- Added OnSizeChange(). Didn't know if I could get rid of the
  OnWidthChange()? Would be nice to remove the Width stuff and
  just have Size (width + height info).
2023-03-04 18:59:22 +09:00
Thomas O'Dowd 586d8eebeb Fix simple race condition related to offset calculations introduced. 2023-02-28 11:09: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
ChenYe 7f93d88cd5 fixing deadloop when input is filtered 2022-07-15 20:48:48 +08:00
mrsinham aee0fa669f fix: on linux multine move was not working (#103)
on linux, if you want to change line, \b are not enough. You need to change line
and move to the right.
2017-10-02 20:39:53 +08:00
Thomas Bradford 707fd8ecaa intercept line rendering using a 'Painter' (#116) 2017-10-01 22:58:28 -05:00
Sagar Mittal 9f56defe66 Add barebones support for yank/paste (#120) 2017-10-01 22:57:50 -05:00
chzyer 283f5429f7 Bugfix/datarace prompt (#81)
* fix data race in PromptLen

* add lock for all operation in RuneBuffer

* add race test

* update travis
2016-09-15 18:11:25 +08:00
chzyer 820d6f2766 fix data race in PromptLen (#80) 2016-09-10 16:03:59 +08:00
chzyer 31eb6be473 support insert tag char (#74) 2016-09-02 20:10:31 +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
aktungmak 47d43db0fd fix #36 vim mode: 'e' moves to the beginning of the next word (#64)
I updated the switch in vim.go to treat 'w' and 'W' differently to 'e' and 'E'.

I then added a method to runebuf.go to provide the logic for that motion.
tested and working.
2016-07-26 21:40:22 +08:00
chzyer 6cc043de37 Fix #43 , remove sub-package for gopkg compatiblity 2016-04-05 09:55:46 +08:00
chzyer 218eb7fff6 [example] Add a IM example 2016-03-31 10:55:53 +08:00
chzyer e5e328dcc7 remove SplitByMultiLine 2016-03-31 00:15:33 +08:00
chzyer b1b67f8632 [runebuffer] use single line 2016-03-30 23:55:12 +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
Chzyer 44ccc71d92 Merge pull request #33 from chzyer/feature/support_more_vim_feature
Support more vim shortcut
2016-02-27 10:07:23 +08:00
Cheney e967bfcedb #22 support more vim shortcut
* c<motion>, d<motion> (change, delete)
* x (delete character)
* r (replace character)
2016-02-24 22:35:22 +08:00
Ben Darnell c3db9c3189 Fix a division by zero on terminals that report 0 width.
This is true of emacs shell-mode.
2016-02-18 17:25:32 -05:00
Cheney 15e7be4ac2 add new interface and fixed crash if stdout isn't a tty 2016-02-18 11:25:41 +08:00
Cheney 00e1a8e95a #19 fixed mass history 2016-02-17 22:20:03 +08:00
Cheney 71e9536f4b add password support 2015-11-20 20:56:42 +08:00
Cheney 55809b401d add runes package 2015-10-04 21:56:34 +08:00
Cheney 879224ddc9 refactor 2015-10-02 10:37:21 +08:00
Cheney 79d1bf27b4 add simple vim mode 2015-10-01 22:44:43 +08:00
Cheney 390f0ebb6b fix typo 2015-09-30 16:13:36 +08:00
Cheney 6eb29567f6 support ANSI escape sequence for windows 2015-09-29 21:01:17 +08:00
Cheney 9edb463230 add windows api, ansi writer 2015-09-29 17:49:58 +08:00
Cheney d4826eb059 add ansi writer 2015-09-29 00:26:49 +08:00
Cheney 03d201ab65 add Ctrl+U 2015-09-28 11:13:39 +08:00
Cheney 7537bea372 add set prompt 2015-09-27 18:54:26 +08:00
Cheney a81fb5db7a fixed not working in screen #3 2015-09-27 10:12:15 +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 a659448259 update example 2015-09-23 14:52:45 +08:00
Cheney 3c4b5dd53d rename 2015-09-23 13:52:26 +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 3f23122fec support save history item 2015-09-22 18:16:24 +08:00
Cheney c8f8ec4b96 refactor runebuffer 2015-09-22 17:41:14 +08:00
Cheney f8c012aa53 fix runebuf 2015-09-22 17:36:52 +08:00
Cheney c9aba7b858 fix deleteword/kill 2015-09-21 22:51:48 +08:00
Cheney 9c65cb7ccf fix runebuffer refresh 2015-09-21 22:27:40 +08:00