Commit Graph

948 Commits

Author SHA1 Message Date
u_quark
8c28483a5e
Add 24 bit color demo 2022-03-21 00:29:26 +00:00
u_quark
a4002d63b7
Fix tests for full color support 2022-03-21 00:29:26 +00:00
u_quark
d304192e98
Read COLORTERM env to determine truecolor support
The environment variable COLORTERM is used by terminal emulators to
signify that they support truecolor in color escape sequences.
2022-03-21 00:29:26 +00:00
Colby Jenn
43c6b3ee4e
add an option to configure 24bit output
create a datatype `ColorMode`, which is stored in `Config`
and `Output`.  It is passed to all of the functions that handle color
processing/output.

Currently this only has one possible value, which gives us the default
vty color handling behavior.

Factor out color drawing code in TerminfoBased.hs

Add datatype for 24-bit colors

Add 24-bit color support

we just write the colors straight to the terminal without using
terminfo.

Move all color-handling info to `ColorMode`

- Add terms for 1/8/16/240 colors to `ColorMode`
- Add function `detectColorMode` to detect color mode

This removes all color-handling information outside of the `ColorMode`
datatype, giving us a single source for color-support information.

This emulates the old color-handling code perfectly pretty much perfectly,
with one exception; For users with >256 colors listed, we don't do anything
special when outputting `Color240`s. The old behavior was absolutely
baffling to me, and seemed like it might cause future issues, so I just
removed it.

Add functions for creating 24-bit colors

- linearColor is just a polymorphic synonym for `RGBColor`
- srgbColor converts inputs from to linear before making a `RGBColor`
- color240 is the same as rgbColor, but with a less confusing name

This is all based of of the assumption that outputs will be linear,
which is true for gnome-terminal, but I haven't tested it with anything
else
2022-03-21 00:29:25 +00:00
Colby Jenn
3d32645d73
minor layout fixes 2022-03-21 00:29:25 +00:00
Jonathan Daugherty
a9e45da79e Make EvResize fields strict now that EvResize is no longer used to handle signals 2022-03-14 15:03:58 -07:00
Jonathan Daugherty
60bd81d684 Rename nit 2022-03-14 13:01:28 -07:00
Jonathan Daugherty
2cd98a862c Wrap internal events in a new InternalEvent type to improve how signal handling is done
This change modifies the Input type's event channel API to produce
InternalEvents, not Events. The new InternalEvent either wraps Event
with the InputEvent constructor (the previous behavior) or indicates
that Vty resumed after handling a signal using the ResumeAfterSignal
constructor. This change avoids the previous use of EvResize with lazy
exception arguments as a sentinel value for ResumeAfterSignal.
2022-03-14 12:56:27 -07:00
Jonathan Daugherty
4969735ce4
Merge pull request #239 from iphydf/lazy-error
fix: Allow unevaluated bottom values in `EvResize`.
2022-03-14 12:19:58 -07:00
iphydf
c979c031d5
fix: Allow unevaluated bottom values in EvResize.
This isn't the ideal fix. I'll look into making a better fix, but this
unbreaks master.
2022-03-14 18:27:33 +00:00
Jonathan Daugherty
e4fb394cdf
Merge pull request #227 from vglfr/master
Handle `Ctrl-h` (backspace) in alacritty
2022-03-12 09:57:44 -08:00
Jonathan Daugherty
daf7641085
Merge pull request #237 from iphydf/scoped-tyvar
cleanup: Make ScopedTypeVariables explicit in files that use it.
2022-03-12 09:29:35 -08:00
iphydf
05a73cc4b3
cleanup: Make ScopedTypeVariables explicit in files that use it. 2022-03-11 15:52:12 +00:00
Jonathan Daugherty
1f4926369e
Merge pull request #236 from iphydf/chunked-processing
perf: Process chunks of bracketed pastes a linear number of times.
2022-03-10 11:56:55 -08:00
iphydf
547ab196fc
perf: Process chunks of bracketed pastes only once.
The current code is `O(n^2)` because it processes the entire input each
time a new chunk arrives. This gets very expensive for large inputs.

This commit changes the code to process each chunk exactly twice: once
to see if it contains the end of the bracketed paste, and another time
to parse the whole paste and return it as an event.

The code can now process more than 1MB/sec. At this point, my tests are
probably more network bound, so these timings might be off, and instead
be testing my network throughput. Good enough for me anyway :).

Timing:
* 1MB: 1s
* 4MB: 3s
* 7MB: 6s
* 10MB: 7s
* 13MB: 10s
* 15MB: 12s
* 20MB: 16s
2022-03-10 00:06:19 +00:00
iphydf
98b2a83da7
perf: Use ByteString instead of [Char] for input parsing.
NOTE: This breaks lots of internal APIs, many of which are actually
exposed as public API. `brick` does not break, but client code that
depends on constants containing escape sequences will need to adapt.

There's really no point in using `[Char]` here. The first thing the code
did was convert all the bytes individually to `Char` and putting them
into a linked list. Then, when actually parsing utf-8, it turns those
`Char`s back into `Word8`s. All the other code is generally concerned
with bytes and goes out of its way to deal with `[Char]` instead. The
code is now simpler and much faster.

Overall this gives another order of magnitude speedup over the previous
speedup totalling roughly a 200x speedup over 2 commits ago for the
300KB case (it's less for smaller cases and much more for larger cases,
because we already made one `n^2` algorithm `n`).

This does not fix the polynomial time complexity, but at this point we
can comfortably paste a low number of megabytes into the terminal and
process it reasonably quickly. This is sufficient to support small file
uploads via bracketed paste.

Some timing:
* 100KB: unmeasurable by hand (basically instant)
* 1000KB: 2 seconds
* 1500KB: 3 seconds
* 2000KB: 5 seconds
* 3000KB: 10 seconds
* 4000KB: 17 seconds
2022-03-10 00:06:11 +00:00
Jonathan Daugherty
2590f05398
Merge pull request #235 from iphydf/fix-pragma
cleanup: Fix invalid pragma.
2022-03-09 15:53:00 -08:00
iphydf
ecee2cd2fc
cleanup: Fix invalid pragma.
Oops. Sorry :\.
2022-03-09 23:09:52 +00:00
Jonathan Daugherty
345f66bba5
Merge pull request #234 from iphydf/unpack
perf: Mark event data types as strict; unpack some fields.
2022-03-09 14:47:46 -08:00
iphydf
9b9635b86b
perf: Mark event data types as strict; unpack some fields.
Integral types like Char and Int benefit a lot from UNPACK. For these,
there is also very little reason to use lazy fields, especially in this
codebase where most computations don't need laziness.
2022-03-09 22:44:24 +00:00
Jonathan Daugherty
d6a069401e
Merge pull request #232 from iphydf/speedup-large-paste
perf: Improve performance for large bracketed pastes.
2022-03-09 11:33:11 -08:00
iphydf
6b8d0639c3
perf: Improve performance for large bracketed pastes.
The current algorithm has polynomial time complexity. The new algorithm
runs in linear time and is generally much more efficient because it
operates on packed byte strings instead of linked lists of Char.

Some timing:
* 100KB: 1 second
* 200KB: 2.5 seconds
* 300KB: 4 seconds
* 400KB: 7 seconds
* 500KB: 12 seconds
* 600KB: 16 seconds
* 700KB: 22 seconds

As we can see, it's still `O(n^2)` overall, probably because of the
calls to `bracketedPasteFinished`. I'll investigate that next. The
constant factor overall is much lower now:
```
Before: 2.866E-6n^3  - 1.784E-4n^2 + 0.114n - 2.622
After:  -1.389E-8n^3 + 5.53E-5n^2  - 1.604E-3n + 0.273
```
2022-03-09 18:49:34 +00:00
Jonathan Daugherty
b3504fbcb0 Bump version, update changelog 2022-02-27 15:23:39 -08:00
Jonathan Daugherty
9891504cfb Fix Cursor constructor documentation order (fixes #229) 2022-01-10 15:36:02 -08:00
Jonathan Daugherty
f8f45c2af5 Remove Monoid and Semigroup instances for Attr and MaybeDefault (relevant to brick/#351)
This change removes the aforementioned instances because they were
misbehaved; merging Attr and MaybeDefault values with these instances
resulted in field value losses. For example, before this change,

  (defAttr `withForeColor` blue) <> (defAttr `withBackColor` green)

would result in just

  (defAttr `withBackColor` green)

because the instances were designed to favor the right-hand arguments'
fields even if they had not been explicitly set (a consequence of the
MaybeDefault Semigroup instance). While that behavior was sensible
specifically in the context of Graphics.Vty.Inline, it wasn't a useful
user-facing API and it made for surprising instance behavior. Since
there is actually no good way to handle this in a Semigroup instance for
Attr -- some choices have to be made about how to merge two attributes'
foreground colors, and that won't be much better than what we had -- the
instance was just removed. I suspect that the risk of this impacting
users negatively is very low, given that the instance behavior was not
very useful.
2021-11-23 15:41:02 -08:00
Jonathan Daugherty
67b25158f9
Merge pull request #228 from mlang/NFData
NFData instance for Event
2021-07-16 08:59:00 -07:00
Mario Lang
a6c346b410 NFData instance for Event 2021-07-16 13:59:16 +02:00
vglfr
e9096594dc
Fix typo in docs 2021-07-15 09:12:44 +03:00
vglfr
a44324a7db
Interpret \b as KBS (for alacritty) 2021-07-15 09:08:17 +03:00
Jonathan Daugherty
abf7fc4cd7 Remove defunct Eq contraints on Semigroup and Monoid instances for MaybeDefault 2021-06-28 05:27:51 -07:00
Jonathan Daugherty
fe501ccf27
Merge pull request #225 from hapytex/improvement/maybedefault-semigroup
A simpler version of the Semigroup instance for MaybeDefault
2021-06-11 05:45:18 -07:00
Willem Van Onsem
b1d5762e0e
revert irrefutable pattern 2021-06-11 08:00:29 +02:00
Willem Van Onsem
e98e94870e
import semigroup 2021-06-10 23:22:57 +02:00
Willem Van Onsem
81b6151d51
irrefutable pattern 2021-06-10 23:15:48 +02:00
Willem Van Onsem
ed04989938
more simplification 2021-06-10 23:15:02 +02:00
Willem Van Onsem
380b618bbf
fix spacing 2021-06-10 23:00:49 +02:00
Willem Van Onsem
e83882c35b
add missing test file 2021-06-10 22:55:31 +02:00
Willem Van Onsem
000f901a93
simplify the Semigroup instance of MaybeDefault 2021-06-10 22:52:17 +02:00
Jonathan Daugherty
fa74b0ae1c
Merge pull request #217 from felixonmars/patch-2
Fix upper bound for `random`
2021-02-24 11:24:29 -08:00
Felix Yan
c0d38a16ba
Fix upper bound for random
It was missing in 05b65fc5bc (diff-bbe7cbd3346ad764f4c6f56880116550ee4f4a768d2a578ede1c0ce22b36fb4f)
2021-02-25 03:13:47 +08:00
Jonathan Daugherty
e953272793 Bump version, update changelog 2021-02-22 17:39:10 -08:00
Jonathan Daugherty
62f5ea36e8
Merge pull request #215 from hapytex/hlint/remove-unused-pragmas
Remove unused LANGUAGE pragmas
2021-02-18 07:30:49 -08:00
Jonathan Daugherty
b21145850c
Merge pull request #216 from hapytex/hlint/redundant-dollar
remove redundant $s
2021-02-18 06:52:28 -08:00
Willem Van Onsem
68ec269cf5
remove redundant $s 2021-02-18 07:40:26 +01:00
Willem Van Onsem
b91829353f remove unused BangPatterns 2021-02-18 07:24:07 +01:00
Willem Van Onsem
152d3d6c07 remove unused NamedFieldPuns 2021-02-18 07:21:23 +01:00
Jonathan Daugherty
fdad9586c4
Merge pull request #214 from hapytex/hlint/atomically-to-io
use readTVarIO and newTVarIO as specialized atomic versions of readTV…
2021-02-17 14:48:41 -08:00
Willem Van Onsem
f0fb92aca0 use readTVarIO and newTVarIO as specialized atomic versions of readTVar and newTVar 2021-02-17 23:46:15 +01:00
Jonathan Daugherty
003f491a43
Merge pull request #212 from hapytex/hlint/group-import
Hlint/group import
2021-02-17 14:41:10 -08:00
Jonathan Daugherty
2a881950de
Merge pull request #213 from hapytex/hlint/use-head
Use head over !!0
2021-02-17 14:40:57 -08:00