ziglibs / ansi-term Goto Github PK
View Code? Open in Web Editor NEWZig library for dealing with ANSI terminals
License: MIT License
Zig library for dealing with ANSI terminals
License: MIT License
Right now, a Style has a foreground color and a background color, which are both of type ?Color
. In my view, this is supposed to represent that a style does not have a foreground or background color, but I think it may be useful to think about changing this.
Proposal: A Style
should represent a complete style which can be drawn onto an ANSI terminal, meaning it is mandatory to specify foreground and background color for a style. But what if an application using this library wants to specify just bold text? Then it can use Color.Default
, a new "pseudo"-color. This also makes everything more explicit and transparent.
Previously, if a Style containing only FontStyle.bold
and null
for foreground and background was applied to a terminal which already had red background applied to it, applying the new style would have a different effect than if the terminal previously had blue background (red and bold vs blue and bold). With the proposed change, programmers apply a Style and can be 100% sure that this specific style is now active on the terminal.
Example of Color.Default
: If the terminal currently has red foreground color and the new Style has Color.Default
foreground color, the ANSI Reset CSI is written.
Do you think it would make sense to include a format
function, so that Style
s can be printed directly?
I added this,
pub fn format(value: Self, comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) std.os.WriteError!void {
try @import("format.zig").updateStyle(writer, value, null);
}
while porting a program away from a different lib, where I had added something similar, and it made the port easy, if suboptimal.
And another thing, when you don't want the cursor to be misplaced, you need yet more escape codes around the bytes that aren't displayed. Currently I have a wrapping writer that adds them as neccessary, but maybe that should be part of the lib in some way?
Would be happy to send patches for those things.
I think it would be nice to include a terminal emulator (basically an interpreter for ANSI escape sequences) in this repository as well. Something along the lines of https://github.com/selectel/pyte for example.
This would enable testing zig libraries and applications which use ANSI escape sequences for correct display without requiring a "real" terminal emulator like xterm
and manually checking the output. Maybe this can even help in developing "real" full-featured terminal emulators.
it seem missing the cursor mode (e.g. blinking, underscore, solid state... )
most of terminal emulator seem support it:
whit N that is 1...6
echo -en "\e[N q"
format
fn for Color
and FontStyle
typesbg
& fg
specifiers for Color type: treat value as background & foreground respectivelynp
: don't write CSI prefix for intelligent updatesAs result:
debug.print("{fg} FG red {bg} BG green {} default", { .Red, .Green, .Reset });
Add a single file that can be added as a package so people can easily use this library
The current build.zig
fails to build on the latest version of zig due to std.build
no longer existing.
/home/hanna/.cache/zig/p/122007393793c7f8e875d4b7c6f8b80ffff936c43a5ed0f21e111574b7ad9b20f897/build.zig:1:31: error: root struct of file 'std' has no member named 'build'
const Builder = @import("std").build.Builder;
~~~~~~~~~~~~~~^~~~~~
/nix/store/h4y9hqs666rgcq2b0g3zmws05ifs28m8-zig-0.12.0-dev.2139+e025ad7b4/lib/std/std.zig:1:1: note: struct declared here
pub const ArrayHashMap = array_hash_map.ArrayHashMap;
^~~
referenced by:
build: /home/hanna/.cache/zig/p/122007393793c7f8e875d4b7c6f8b80ffff936c43a5ed0f21e111574b7ad9b20f897/build.zig:3:18
runBuild__anon_15827: /nix/store/h4y9hqs666rgcq2b0g3zmws05ifs28m8-zig-0.12.0-dev.2139+e025ad7b4/lib/std/Build.zig:1857:50
remaining reference traces hidden; use '-freference-trace' to see all reference traces
Currently, FontStyle
is represented as a (possibly packed after #5) struct of bools.
I think using integer types and bitwise operations, we could achieve better and possibly faster functionality. Consider the following simplified example:
const FontStyle = u3;
const default: FontStyle = 0b000;
const bold: FontStyle = 0b001;
const dim: FontStyle = 0b010;
const italic: FontStyle = 0b100;
Combining font styles can be done with bitwise or; checking for a style can be done with bitwise and.
cc @data-man
I understand the docs generation is not stable yet etc... however it would be nice to have an easy way to read documentation w/o having to read the source for it.
You'll have to google to work out how you can add it as a step in build.zig
I would open a PR but its easier to ask first imo.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.