1
0
mirror of https://github.com/gdamore/tcell.git synced 2025-04-24 13:48:51 +08:00

228 Commits

Author SHA1 Message Date
Garrett D'Amore
197faf3eae fixes #120 Support for bracketed paste mode
This adds Bracketed Paste support for terminals that have mouse
support and support it.  The bracketing events are EventPaste,
with methods to note Start() or End() of the paste.  Content
comes in as normal rune events.  Programs must opt-in to this by
calling screen.EnablePaste().
2020-10-15 23:13:03 -07:00
Garrett D'Amore
aeb3a11948 fixes #391 tcell panic on TERM=xterm-termite
This fixes the panic, but also adds defitions for xterm-termite
and tmux-256color.
2020-10-13 22:17:07 -07:00
Jai Flack
50e36d6c03 Fix CHANGESv2.adoc Import Path
The import path in CHANGESv2.adoc was wrong and didn't match README.adoc.
This fixes that.
2020-10-07 10:42:30 -07:00
qlcom
0fb77ddaa5 add github.com/gokcehan/lf to Examples 2020-09-26 08:21:01 -07:00
Graham Clark
1f9685874a Attempted fix of a regression I introduced - breaking mouse support!
@tslocum reported that the commit at 2d6d7fbe broke mouse support in
cview (https://github.com/gdamore/tcell/pull/384#issuecomment-698422464). The
purpose of the original commit was to fix a terminfo background color
code parsing problem that I spotted using TERM=xterm-16color:

$ infocmp xterm-16color | grep setab
	setab=\E[%?%p1%{8}%<%t%p1%'('%+%e%p1%{92}%+%;%dm,

The middle sections says "if p1<8 then push(p1+'(') ". '(' is ascii
40. The sequence '%d' will then pop from the stack and interpreting the
result as an integer.

My change above was to have tcell assume the sequence between two single
quotes was a single ASCII character e.g. '(' and push that to the
terminfo stack as an integer with the ASCII value of the character
e.g. push(40:int). I didn't find any counterexamples in my local
terminfo database that didn't line up with that assumption; but I did
break mouse support because tcell generates its own rules to enable
mouse support, if not specified in the terminfo DB - both when
generating its own Golang-style internal DB, and in the dynamic terminfo
generator that uses infocmp:

"%?%p1%{1}%=%t%'h'%Pa%e%'l'%Pa%;\x1b[?1000%ga%c\x1b[?1002%ga%c\x1b[?1003%ga%c\x1b[?1006%ga%c"

This rule will push 'h' or 'l', depending on whether mouse mode is to be
enabled or disabled, and then sets the variable named a to the result,
interpreted as a string. The result is that when mouse mode is enabled,
tcell needs to emit \x1b[?1000h - where the 'h' comes from variable a
i.e. it needs to be able to push a quoted argument as a string and not
be forced into an int.

This alternative fix preserves the fact the quoted argument is a string
and maintains that on the stack. However, if the integer Pop() function
is called when the top element of the stack is a string, tcell will now

- return the string converted to an int, if it converts e.g. in the case
  '123' is pushed to the stack as a string and popped as an int, the value
  is 123
- otherwise return the ASCII value of the first character of the string
  e.g. if '(' is pushed then popped as an int, the value returned is 40.

To be compatible with this logic, if a terminfo rule needs to push an
integer whose value is >= ascii('0')==48 and <= ascii('9')==57, it will
need to use the form e.g. {53} and not '5' because the form '5' will be
pushed as "5":string and if popped as an int will return the value 5 and
not 53.
2020-09-26 08:19:27 -07:00
Marcel Schramm
0cc2ea7214 Fixed typo in example link description
There was a typo in my previous PR, I didn't notice, sorry
2020-09-24 14:17:53 -07:00
Marcel Schramm
6c71be6801 Add Bios-Marcel/memoryalike to the readme
I added a link to https://github.com/Bios-Marcel/memoryalike.
It's a small terminal game written with tcell as it's sole dependency.
2020-09-21 11:39:46 -07:00
Graham Clark
2d6d7fbe48 Change interpretation of pushing quoted character in terminfo parser
I noticed this problem while running a gowid test program (palette.go)
with TERM=xterm-16color. This terminal type is not present in tcell's
built-in database, and so tcell falls back to the dynamic terminal type
by parsing the output of infocmp. The symptom was that foreground colors
were not correctly set, leaving a monochrome screen. This seems to be
caused by a problem interpreting the *background* color terminfo
rule. The attribute to set background color is defined like this (Ubuntu
20.04):

$ infocmp xterm-16color | grep setab
	setab=\E[%?%p1%{8}%<%t%p1%'('%+%e%p1%{92}%+%;%dm,

The middle sections says "if p1<8 then push(p1+'(') ". '(' is ascii
40. If I run

$ tput setab 5

the terminal sees 'ESC[45m'. This correctly sets the background color to
magenta. But if I tell tcell to emit a cell with background color set to
tcell.Color(5), the terminal sees 'ESC[0m'. This means in practice, my
app emits a code to set the foreground color, then an SGR code that
resets all attributes, then the ASCII character.

When tcell "runs" a terminfo rule in terminfo::TParm(), a push to the
stack preserves the type of the argument pushed - int or string. When a
single quote is encountered, the argument within is pushed to the stack
as a string. For the `setab` rule above, tcell will then pop as an int,
discarding the error and returning 0. The fix here is to have tcell push
the argument inside the single quotes as an integer, using the ascii
value of the argument e.g. "(" -> 40 - and assume the string is length
1, I suppose. Cross-referencing against
ncurses/tinfo/lib_tinfo.c::tparam_internal(), it looks like this code
assumes a single-quoted string is assumed to be length=1 and is also
interpreted as an integer with the ascii value of the character:

case S_QUOTE:
    cp++;
    npush(UChar(*cp));
    cp++;
    break;
2020-09-20 08:17:17 -07:00
Magnus
222a03c3db Added two more examples 2020-09-20 08:12:58 -07:00
Eze Olea Figueroa
0c5e1e1720 Added Tblogs to README 2020-09-08 05:12:50 -07:00
Trevor Slocum
da485f4734 Rename StrikeOut as StrikeThrough 2020-08-31 08:55:31 -07:00
Garrett D'Amore
c008cc6a3b Add CHANGESv2 to track important changes for V2 (breaking changes). 2020-08-30 23:40:01 -07:00
Garrett D'Amore
368f8e092b fixes #376 Need ColorReset
This provides a ColorReset color that resets the color to
the default for the terminal.
2020-08-30 22:57:00 -07:00
Garrett D'Amore
9d283802ab fixes #350 Add strikeout support 2020-08-30 20:25:30 -07:00
Garrett D'Amore
7e218720b8 Remove stray sleep 2020-08-30 20:11:55 -07:00
Garrett D'Amore
bf3f269ccb fixes #373 Check for and use RGB property in terminfo
This also regenerated some definitions, which should lead to
more accurate mouse mode for a few of the terminals.
2020-08-30 19:33:25 -07:00
Garrett D'Amore
5216188a4f fixes #324 Fini() is not idempotent 2020-08-30 19:00:54 -07:00
Garrett D'Amore
2323e87243 fixes #372 tmux terminal entry needed 2020-08-30 18:53:47 -07:00
Garrett D'Amore
23606a43e2 fixes #319 Pasting on windows still does a maximum of 10 characters
The Windows input scanner does not hold the screen lock, so we can
safely just block if we need to, so we use PostEventWait().
2020-08-30 03:03:47 -07:00
Garrett D'Amore
59ebfab322 fixes #309 Broken backtab key on st. 2020-08-30 02:36:32 -07:00
Garrett D'Amore
ea5ae53b7f This is Tcell, not mangos! 2020-08-30 02:34:04 -07:00
Garrett D'Amore
84d0c5503d fixes #369 Better support for modifier keys
This replaces high numbered function keys on xterm style
emulators with modifiers.  So pressing SHIFT-ALT-F1 is
reported as exactly that, for example.  This also extends
that to the insert, delete, home, end, etc.

There is a chance that this will break some emulators --
of particular concern are older VTE based emulators and
rxvt (and derivatives).  However, we think that most VTE
derivatives are now much more closely aligned to xterm.

The Wyse50 alternate character set was changed (likely
due to a bug fix in ncurses).
2020-08-30 02:11:39 -07:00
Garrett D'Amore
cc28e81105 fixes #370 Retire some old terminals 2020-08-30 01:58:02 -07:00
Elliott Sales de Andrade
b0881963db Add missing entries to models.txt.
Otherwise, deleting all `term.go` and re-running `bash gen.sh` does
_not_ produce everything again.
2020-08-27 11:05:36 -07:00
qlcom
b055e05f63 README: Add aerc to Example 2020-08-27 11:04:25 -07:00
Hubert Hirtz
a6386839fd Add italic code to alacritty terminfo 2020-08-26 07:01:04 -07:00
Garrett D'Amore
5889c5f171 fixes #314 Implement setf & setb
This causes colors that are set that are low numbered to
be treated as themed colors -- basically honoring the palette
of the terminal.

The Style and Color implementations have changed quite a bit
to permit growth -- the colors are now 64-bits wide to permit
using the upper bits as flags, and to leave room for a future
alpha channel.

There is a new TrueColor() method on colors that obtains the
value as strict RGB value, and this will be used in lieu of
whatever terminal colors are provided -- giving the application
full control over the color space if they want, without
forcibly clobbering user preferences for terminals for the
vast majority of cases.

Indexed colors are created with the new PaletteColor API.
2020-08-25 22:26:48 -07:00
Garrett D'Amore
8a32d2b0c8 Version 2.0 work in progress. v2.0.0-dev 2020-08-25 16:20:58 -07:00
Garrett D'Amore
5bef26acc2 fixes #358 EventMouse button mapping 2020-08-25 15:39:20 -07:00
Garrett D'Amore
fcaa20f283 minor readme updates v1.4.0 2020-08-25 15:26:09 -07:00
Garrett D'Amore
0c473b86d8 fixes #187 24-bit color for Windows 10 console
This works well on the new Windows 10 Terminal, as well as recent
Windows 10 ConHost.  Support for this is automatically enabled if
we detect that the terminal supports ANSI escapes, except for
ConEmu, which has a fairly severe scrolling bug with truecolor.

To opt-in anyway, set TCELL_TRUECOLOR to "enable" in your environment.

To opt-out, set TCELL_TRUECOLOR to "disable" in your environment.
2020-08-25 08:10:11 -07:00
Davor Najev
776d98d385 Add tpong to examples list 2020-08-23 15:13:37 -07:00
codesoap
ad515f0702 Add "Hello, World!" demo 2020-08-23 10:07:39 -07:00
Trevor Slocum
79a04f1021 Add cbind to examples
Resolves #333.
2020-06-20 14:43:05 -07:00
Endre Simo
cb1e5d6fa6 Include ascii-fluid into examples list 2020-06-08 06:33:53 -07:00
Garrett D'Amore
4b435a5197 Revert "allocate buffer once, outside the key loop"
This reverts commit 1b5e88726b02c4d65b5a921ba06f016708ef0f9d.

Reuse of the buffer causes a subtle bug if the consumer
does not read from the slice fast enough.  This was a regression.
2020-06-07 13:38:21 -07:00
VÖRÖSKŐI András
b0084cc526 Remove SetCursor(0,0) from CellArea SetModel
Removing SetCursor makes it possible to add lines to the model on the fly,
while keeping the cursor in position.

Go also initializes them with 0, no need to set it manually.
2020-05-27 19:47:21 -07:00
milrope
0a41e34912 Add fzf to example 2020-05-27 19:46:30 -07:00
Jeff Warner
74eda0d093 Mark tui-go as deprecated
As mentioned at on its homepage, the project is no longer being maintained and has been archived
2020-05-27 19:45:07 -07:00
Joshua M. Clulow
157ccd71a2 fix build on illumos after Beep() API
The build for the "solaris" and "illumos" tags appears to have been
broken by commit 8ec73b6fa6c543d5d067722c0444b07f7607ba2f, which
introduced the Beep() API.  Restore functionality by using the same
implementation as every other UNIX family platform.
2020-05-27 19:43:05 -07:00
VÖRÖSKŐI András
e277d9c03b Fix TextArea SetContent method
SetContent should overwrite the model, not append to it.

Add a test to check model's width and height after SetContent calls.
2020-05-07 07:39:48 -07:00
VÖRÖSKŐI András
1f1f979c1b TextArea: use [][]rune instead of []string in linesModel
This way GetCell() will get full runes, not just bytes. Now accent characters will show properly

Adjust SetLines() and Init() to work on [][]rune instead of []string
2020-04-13 12:51:31 -07:00
Nojus Gudinavičius
8572f72a22 Add support for italics 2020-04-13 07:15:39 -07:00
Martin Angers
1b5e88726b allocate buffer once, outside the key loop 2020-04-13 07:13:55 -07:00
Ben Burwell
8ec73b6fa6 Implement Beep() API
Add a Beep() method to the Screen interface. On *nix systems, this
writes the bell character (0x07) to the tty. On Windows, we call the
MessageBeep syscall.

Fixes: #2
2020-03-15 10:36:32 -07:00
Anatoly Rugalev
96a065d8ff Fixed text incorrect width calculation for multiline strings 2020-03-15 10:34:41 -07:00
VÖRÖSKŐI András
b03a4607a4 Add GetModel() method to CellView
GetModel() returns CellView.model type CellModel
2020-02-28 11:53:41 -08:00
VÖRÖSKŐI András
66b1faf255 CeellView corsor remove
Do not store cursor info (cursorX, CursorY) in CellView, as it belongs to the model (CellModel)

Use GetCursor() to identify current cursor position from CellModel
2020-02-28 11:53:41 -08:00
Vedran Vidović
bac2bbc5b3 Adding Shift modifier for PgUp/PgDn
Implemented key kombination of Shift + PgUp/PgDn for Gnome terminal.
Same combination copied to all other terminal implementations which use same
codes for Shift + Up/Down but since this is tested on Ubuntu 16.04 with Gnome
Terminal 3.18.3 it could be that it is not correctly implemented for some of the
other terminals.
2020-02-05 21:47:23 -08:00
Graham Clark
bff4943f9a Provide a fallback terminal size if the OS returns (0,0)
Sometimes, the TIOCGWINSZ ioctl returns all zeroes (including columns,
rows) without an error. I found this when experimenting with the jexer
TUI toolkit for java e.g.

mvn dependency:get -Dartifact=com.gitlab.klamonte:jexer:0.3.2
jexer -jar ~/.m2/repository/com/gitlab/klamonte/jexer/0.3.2/jexer-0.3.2.jar

Once the demo starts, click the "Terminal" button, then type

stty size

it returns

0 0

My understanding is that this is normal, and happens until SIGWINCH is
received, or the size is set explicitly with TIOCSWINSZ.

My tcell application crashed under the jexer terminal because I didn't
anticipate a window size of (0,0).

If you run vim under the jexer terminal, it correctly sizes itself to
80x24. The shell's TERM variable is xterm, and infocmp xterm | grep cols
shows a default of 80 and a default of 24 for lines. The documentation
for vim explains how it computes the terminal size:

https://github.com/vim/vim/blob/master/runtime/doc/term.txt#L629

- an ioctl call (TIOCGSIZE or TIOCGWINSZ, depends on your system)
- the environment variables "LINES" and "COLUMNS"
- from the termcap entries "li" and "co"

This PR replicates that logic in the getWinSize() function. I think it
makes sense here because tScreen holds the TermInfo struct but the
tcell.Screen interface does not expose TermInfo to clients - of course
because the screen is abstracted to work on Windows too.
2020-01-14 19:03:18 -08:00