Giter Club home page Giter Club logo

term's Introduction

term

A Rust library for terminfo parsing and terminal colors.

CI

Documentation

MSRV

1.36 - the minimum version testable on circleci.

Usage

Add this to your Cargo.toml:

[dependencies]

term = "*"

Packaging and Distributing

For all terminals but windows consoles, this library depends on a non-hashed (for now) terminfo database being present. For example, on Debian derivitives, you should depend on ncurses-term; on Arch Linux, you depend on ncurses; and on MinGW, you should depend on mingw32-terminfo.

Unfortunately, if you're using a non-windows console on Windows (e.g. MinGW, Cygwin, Git Bash), you'll need to set the TERMINFO environment variable to point to the directory containing the terminfo database.

term's People

Contributors

alexcrichton avatar asolove avatar brson avatar derekdreery avatar dimbleby avatar eijebong avatar emberian avatar fkohlgrueber avatar frewsxcv avatar hannobraun avatar huonw avatar ignatenkobrain avatar ivanukhov avatar lukaslueg avatar marcoieni avatar mgeisler avatar mkpankov avatar mosal avatar msiemens avatar o01eg avatar ogham avatar oherrala avatar retep998 avatar rhysd avatar shepmaster avatar snim2 avatar sourcefrog avatar stebalien avatar swolchok avatar syvb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

term's Issues

better support for multithreaded programs

@Stebalien First off, thank you for maintaining this wonderful library. :-)

I came across a particular issue with the current API. Specifically, TerminfoTerminal::new_with_terminfo takes ownership over a TermInfo. Even though TermInfo is never mutated by a TerminfoTerminal, a TermInfo cannot be reused across multiple TerminfoTerminal values. In particular, the only way to amortize the cost of building a TermInfo is to clone it, but even this can be costly.

I'm not sure what the right API is, but I will note that using Arc solves my specific problem (which permits very cheap multithreaded read-only access).

There are potentially many other solutions, all with their own downsides:

  1. Require Arc<TermInfo> instead of TermInfo, but this feels a little strange to me.
  2. Require <T: AsRef<TermInfo>>. This means TermInfoTerminal will need to grow a type parameter.
  3. Define a new trait with the existing methods on TermInfo and require that. This also requires an additional type parameter.
  4. Make TermInfo an opaque struct and use an Arc internally, which will make cloning trivially cheap.

Other ideas? Thoughts?

terminfo problem while using rogcat

Hi,

referring to flxo/rogcat#13

I'm not able to launch rogcat that is reporting a Failed to lock terminal because of a term problem. As discussed in the linked issue the problem might be related with parsing terminfo files

Some extra info about my machine:

Linux x1 4.14.27-1-MANJARO #1 SMP PREEMPT Thu Mar 15 19:47:13 UTC 2018 x86_64 GNU/Linux
ncurses 6.1-3
xterm 331-1
cargo 0.25.0 (96d8071da 2018-02-26)
rustc 1.24.1 (d3ae9a9e0 2018-02-27)

Could you please help me?

Failed to compile with latest Nightly

Failed to compile with latest Nightly rustc 1.3.0-nightly (20f421cd5 2015-07-06)

$ cargo test --verbose
   Compiling libc v0.1.8
     Running `rustc /home/user/.cargo/registry/src/github.com-0a35038f75765ae4/libc-0.1.8/rust/src/liblibc/lib.rs --crate-name libc --crate-type lib -g --cfg feature=\"default\" --cfg feature=\"cargo-build\" -C metadata=ef5cbad4ef5c7a1e -C extra-filename=-ef5cbad4ef5c7a1e --out-dir /home/user/MaidSafe-Testing/term/target/debug/deps --emit=dep-info,link -L dependency=/home/user/MaidSafe-Testing/term/target/debug/deps -L dependency=/home/user/MaidSafe-Testing/term/target/debug/deps -Awarnings`
   Compiling winapi-build v0.1.0
     Running `rustc /home/user/.cargo/registry/src/github.com-0a35038f75765ae4/winapi-build-0.1.0/src/lib.rs --crate-name build --crate-type lib -g -C metadata=5e403cad040f7862 -C extra-filename=-5e403cad040f7862 --out-dir /home/user/MaidSafe-Testing/term/target/debug/deps --emit=dep-info,link -L dependency=/home/user/MaidSafe-Testing/term/target/debug/deps -L dependency=/home/user/MaidSafe-Testing/term/target/debug/deps -Awarnings`
   Compiling winapi v0.1.23
     Running `rustc /home/user/.cargo/registry/src/github.com-0a35038f75765ae4/winapi-0.1.23/src/lib.rs --crate-name winapi --crate-type lib -g -C metadata=fbb144edd0d77a8f -C extra-filename=-fbb144edd0d77a8f --out-dir /home/user/MaidSafe-Testing/term/target/debug/deps --emit=dep-info,link -L dependency=/home/user/MaidSafe-Testing/term/target/debug/deps -L dependency=/home/user/MaidSafe-Testing/term/target/debug/deps --extern libc=/home/user/MaidSafe-Testing/term/target/debug/deps/liblibc-ef5cbad4ef5c7a1e.rlib -Awarnings`
   Compiling kernel32-sys v0.1.2
     Running `rustc /home/user/.cargo/registry/src/github.com-0a35038f75765ae4/kernel32-sys-0.1.2/build.rs --crate-name build_script_build --crate-type bin -C prefer-dynamic -g --out-dir /home/user/MaidSafe-Testing/term/target/debug/build/kernel32-sys-7ae262b5d3e8acdb --emit=dep-info,link -L dependency=/home/user/MaidSafe-Testing/term/target/debug/deps -L dependency=/home/user/MaidSafe-Testing/term/target/debug/deps --extern build=/home/user/MaidSafe-Testing/term/target/debug/deps/libbuild-5e403cad040f7862.rlib -Awarnings`
     Running `/home/user/MaidSafe-Testing/term/target/debug/build/kernel32-sys-7ae262b5d3e8acdb/build-script-build`
     Running `rustc /home/user/.cargo/registry/src/github.com-0a35038f75765ae4/kernel32-sys-0.1.2/src/lib.rs --crate-name kernel32 --crate-type lib -g -C metadata=7ae262b5d3e8acdb -C extra-filename=-7ae262b5d3e8acdb --out-dir /home/user/MaidSafe-Testing/term/target/debug/deps --emit=dep-info,link -L dependency=/home/user/MaidSafe-Testing/term/target/debug/deps -L dependency=/home/user/MaidSafe-Testing/term/target/debug/deps --extern winapi=/home/user/MaidSafe-Testing/term/target/debug/deps/libwinapi-fbb144edd0d77a8f.rlib -Awarnings`
   Compiling term v0.2.9 (file:///home/user/MaidSafe-Testing/term)
     Running `rustc src/lib.rs --crate-name term --crate-type lib -g --out-dir /home/user/MaidSafe-Testing/term/target/debug --emit=dep-info,link -L dependency=/home/user/MaidSafe-Testing/term/target/debug -L dependency=/home/user/MaidSafe-Testing/term/target/debug/deps --extern winapi=/home/user/MaidSafe-Testing/term/target/debug/deps/libwinapi-fbb144edd0d77a8f.rlib --extern kernel32=/home/user/MaidSafe-Testing/term/target/debug/deps/libkernel32-7ae262b5d3e8acdb.rlib`
     Running `rustc src/lib.rs --crate-name term --crate-type lib -g --test -C metadata=01a33fd622846cc0 -C extra-filename=-01a33fd622846cc0 --out-dir /home/user/MaidSafe-Testing/term/target/debug --emit=dep-info,link -L dependency=/home/user/MaidSafe-Testing/term/target/debug -L dependency=/home/user/MaidSafe-Testing/term/target/debug/deps --extern winapi=/home/user/MaidSafe-Testing/term/target/debug/deps/libwinapi-fbb144edd0d77a8f.rlib --extern kernel32=/home/user/MaidSafe-Testing/term/target/debug/deps/libkernel32-7ae262b5d3e8acdb.rlib`
src/terminfo/parser/compiled.rs:22:1: 32:28 error: missing documentation for a static
src/terminfo/parser/compiled.rs:22 pub static boolfnames: &'static[&'static str] = &["auto_left_margin", "auto_right_margin",
src/terminfo/parser/compiled.rs:23     "no_esc_ctlc", "ceol_standout_glitch", "eat_newline_glitch", "erase_overstrike", "generic_type",
src/terminfo/parser/compiled.rs:24     "hard_copy", "has_meta_key", "has_status_line", "insert_null_glitch", "memory_above",
src/terminfo/parser/compiled.rs:25     "memory_below", "move_insert_mode", "move_standout_mode", "over_strike", "status_line_esc_ok",
src/terminfo/parser/compiled.rs:26     "dest_tabs_magic_smso", "tilde_glitch", "transparent_underline", "xon_xoff", "needs_xon_xoff",
src/terminfo/parser/compiled.rs:27     "prtr_silent", "hard_cursor", "non_rev_rmcup", "no_pad_char", "non_dest_scroll_region",
                                   ...
src/lib.rs:63:9: 63:21 note: lint level defined here
src/lib.rs:63 #![deny(missing_docs)]
                      ^~~~~~~~~~~~
src/terminfo/parser/compiled.rs:34:1: 37:92 error: missing documentation for a static
src/terminfo/parser/compiled.rs:34 pub static boolnames: &'static[&'static str] = &["bw", "am", "xsb", "xhp", "xenl", "eo",
src/terminfo/parser/compiled.rs:35     "gn", "hc", "km", "hs", "in", "db", "da", "mir", "msgr", "os", "eslok", "xt", "hz", "ul", "xon",
src/terminfo/parser/compiled.rs:36     "nxon", "mc5i", "chts", "nrrmc", "npc", "ndscr", "ccc", "bce", "hls", "xhpa", "crxm", "daisy",
src/terminfo/parser/compiled.rs:37     "xvpa", "sam", "cpix", "lpix", "OTbs", "OTns", "OTnc", "OTMT", "OTNL", "OTpt", "OTxr"];
src/lib.rs:63:9: 63:21 note: lint level defined here
src/lib.rs:63 #![deny(missing_docs)]
                      ^~~~~~~~~~~~
src/terminfo/parser/compiled.rs:39:1: 47:93 error: missing documentation for a static
src/terminfo/parser/compiled.rs:39 pub static numfnames: &'static[&'static str] = &[ "columns", "init_tabs", "lines",
src/terminfo/parser/compiled.rs:40     "lines_of_memory", "magic_cookie_glitch", "padding_baud_rate", "virtual_terminal",
src/terminfo/parser/compiled.rs:41     "width_status_line", "num_labels", "label_height", "label_width", "max_attributes",
src/terminfo/parser/compiled.rs:42     "maximum_windows", "max_colors", "max_pairs", "no_color_video", "buffer_capacity",
src/terminfo/parser/compiled.rs:43     "dot_vert_spacing", "dot_horz_spacing", "max_micro_address", "max_micro_jump", "micro_col_size",
src/terminfo/parser/compiled.rs:44     "micro_line_size", "number_of_pins", "output_res_char", "output_res_line",
                                   ...
src/lib.rs:63:9: 63:21 note: lint level defined here
src/lib.rs:63 #![deny(missing_docs)]
                      ^~~~~~~~~~~~
src/terminfo/parser/compiled.rs:49:1: 52:81 error: missing documentation for a static
src/terminfo/parser/compiled.rs:49 pub static numnames: &'static[&'static str] = &[ "cols", "it", "lines", "lm", "xmc", "pb",
src/terminfo/parser/compiled.rs:50     "vt", "wsl", "nlab", "lh", "lw", "ma", "wnum", "colors", "pairs", "ncv", "bufsz", "spinv",
src/terminfo/parser/compiled.rs:51     "spinh", "maddr", "mjump", "mcs", "mls", "npins", "orc", "orl", "orhi", "orvi", "cps", "widcs",
src/terminfo/parser/compiled.rs:52     "btns", "bitwin", "bitype", "UTug", "OTdC", "OTdN", "OTdB", "OTdT", "OTkn"];
src/lib.rs:63:9: 63:21 note: lint level defined here
src/lib.rs:63 #![deny(missing_docs)]
                      ^~~~~~~~~~~~
src/terminfo/parser/compiled.rs:54:1: 125:64 error: missing documentation for a static
src/terminfo/parser/compiled.rs:54 pub static stringfnames: &'static[&'static str] = &[ "back_tab", "bell", "carriage_return",
src/terminfo/parser/compiled.rs:55     "change_scroll_region", "clear_all_tabs", "clear_screen", "clr_eol", "clr_eos",
src/terminfo/parser/compiled.rs:56     "column_address", "command_character", "cursor_address", "cursor_down", "cursor_home",
src/terminfo/parser/compiled.rs:57     "cursor_invisible", "cursor_left", "cursor_mem_address", "cursor_normal", "cursor_right",
src/terminfo/parser/compiled.rs:58     "cursor_to_ll", "cursor_up", "cursor_visible", "delete_character", "delete_line",
src/terminfo/parser/compiled.rs:59     "dis_status_line", "down_half_line", "enter_alt_charset_mode", "enter_blink_mode",
                                   ...
src/lib.rs:63:9: 63:21 note: lint level defined here
src/lib.rs:63 #![deny(missing_docs)]
                      ^~~~~~~~~~~~
src/terminfo/parser/compiled.rs:127:1: 159:13 error: missing documentation for a static
src/terminfo/parser/compiled.rs:127 pub static stringnames: &'static[&'static str] = &[ "cbt", "_", "cr", "csr", "tbc", "clear",
src/terminfo/parser/compiled.rs:128     "_", "_", "hpa", "cmdch", "cup", "cud1", "home", "civis", "cub1", "mrcup", "cnorm", "cuf1",
src/terminfo/parser/compiled.rs:129     "ll", "cuu1", "cvvis", "dch1", "dl1", "dsl", "hd", "smacs", "blink", "bold", "smcup", "smdc",
src/terminfo/parser/compiled.rs:130     "dim", "smir", "invis", "prot", "rev", "smso", "smul", "ech", "rmacs", "sgr0", "rmcup", "rmdc",
src/terminfo/parser/compiled.rs:131     "rmir", "rmso", "rmul", "flash", "ff", "fsl", "is1", "is2", "is3", "if", "ich1", "il1", "ip",
src/terminfo/parser/compiled.rs:132     "kbs", "ktbc", "kclr", "kctab", "_", "_", "kcud1", "_", "_", "_", "_", "_", "_", "_", "_", "_",
                                    ...
src/lib.rs:63:9: 63:21 note: lint level defined here
src/lib.rs:63 #![deny(missing_docs)]
                      ^~~~~~~~~~~~
src/lib.rs:135:5: 135:34 error: missing documentation for a constant
src/lib.rs:135     pub const BLACK:   Color = 0;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:63:9: 63:21 note: lint level defined here
src/lib.rs:63 #![deny(missing_docs)]
                      ^~~~~~~~~~~~
src/lib.rs:136:5: 136:34 error: missing documentation for a constant
src/lib.rs:136     pub const RED:     Color = 1;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:63:9: 63:21 note: lint level defined here
src/lib.rs:63 #![deny(missing_docs)]
                      ^~~~~~~~~~~~
src/lib.rs:137:5: 137:34 error: missing documentation for a constant
src/lib.rs:137     pub const GREEN:   Color = 2;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:63:9: 63:21 note: lint level defined here
src/lib.rs:63 #![deny(missing_docs)]
                      ^~~~~~~~~~~~
src/lib.rs:138:5: 138:34 error: missing documentation for a constant
src/lib.rs:138     pub const YELLOW:  Color = 3;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:63:9: 63:21 note: lint level defined here
src/lib.rs:63 #![deny(missing_docs)]
                      ^~~~~~~~~~~~
src/lib.rs:139:5: 139:34 error: missing documentation for a constant
src/lib.rs:139     pub const BLUE:    Color = 4;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:63:9: 63:21 note: lint level defined here
src/lib.rs:63 #![deny(missing_docs)]
                      ^~~~~~~~~~~~
src/lib.rs:140:5: 140:34 error: missing documentation for a constant
src/lib.rs:140     pub const MAGENTA: Color = 5;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:63:9: 63:21 note: lint level defined here
src/lib.rs:63 #![deny(missing_docs)]
                      ^~~~~~~~~~~~
src/lib.rs:141:5: 141:34 error: missing documentation for a constant
src/lib.rs:141     pub const CYAN:    Color = 6;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:63:9: 63:21 note: lint level defined here
src/lib.rs:63 #![deny(missing_docs)]
                      ^~~~~~~~~~~~
src/lib.rs:142:5: 142:34 error: missing documentation for a constant
src/lib.rs:142     pub const WHITE:   Color = 7;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:63:9: 63:21 note: lint level defined here
src/lib.rs:63 #![deny(missing_docs)]
                      ^~~~~~~~~~~~
src/lib.rs:144:5: 144:41 error: missing documentation for a constant
src/lib.rs:144     pub const BRIGHT_BLACK:   Color = 8;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:63:9: 63:21 note: lint level defined here
src/lib.rs:63 #![deny(missing_docs)]
                      ^~~~~~~~~~~~
src/lib.rs:145:5: 145:41 error: missing documentation for a constant
src/lib.rs:145     pub const BRIGHT_RED:     Color = 9;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:63:9: 63:21 note: lint level defined here
src/lib.rs:63 #![deny(missing_docs)]
                      ^~~~~~~~~~~~
src/lib.rs:146:5: 146:42 error: missing documentation for a constant
src/lib.rs:146     pub const BRIGHT_GREEN:   Color = 10;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:63:9: 63:21 note: lint level defined here
src/lib.rs:63 #![deny(missing_docs)]
                      ^~~~~~~~~~~~
src/lib.rs:147:5: 147:42 error: missing documentation for a constant
src/lib.rs:147     pub const BRIGHT_YELLOW:  Color = 11;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:63:9: 63:21 note: lint level defined here
src/lib.rs:63 #![deny(missing_docs)]
                      ^~~~~~~~~~~~
src/lib.rs:148:5: 148:42 error: missing documentation for a constant
src/lib.rs:148     pub const BRIGHT_BLUE:    Color = 12;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:63:9: 63:21 note: lint level defined here
src/lib.rs:63 #![deny(missing_docs)]
                      ^~~~~~~~~~~~
src/lib.rs:149:5: 149:42 error: missing documentation for a constant
src/lib.rs:149     pub const BRIGHT_MAGENTA: Color = 13;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:63:9: 63:21 note: lint level defined here
src/lib.rs:63 #![deny(missing_docs)]
                      ^~~~~~~~~~~~
src/lib.rs:150:5: 150:42 error: missing documentation for a constant
src/lib.rs:150     pub const BRIGHT_CYAN:    Color = 14;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:63:9: 63:21 note: lint level defined here
src/lib.rs:63 #![deny(missing_docs)]
                      ^~~~~~~~~~~~
src/lib.rs:151:5: 151:42 error: missing documentation for a constant
src/lib.rs:151     pub const BRIGHT_WHITE:   Color = 15;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:63:9: 63:21 note: lint level defined here
src/lib.rs:63 #![deny(missing_docs)]
                      ^~~~~~~~~~~~
error: aborting due to 22 previous errors
Build failed, waiting for other jobs to finish...
Could not compile `term`.

Caused by:
  Process didn't exit successfully: `rustc src/lib.rs --crate-name term --crate-type lib -g --out-dir /home/user/MaidSafe-Testing/term/target/debug --emit=dep-info,link -L dependency=/home/user/MaidSafe-Testing/term/target/debug -L dependency=/home/user/MaidSafe-Testing/term/target/debug/deps --extern winapi=/home/user/MaidSafe-Testing/term/target/debug/deps/libwinapi-fbb144edd0d77a8f.rlib --extern kernel32=/home/user/MaidSafe-Testing/term/target/debug/deps/libkernel32-7ae262b5d3e8acdb.rlib` (exit code: 101)

Term crashes on FreeBSD

Running the example program:

extern crate term;
use std::io::prelude::*;

fn main() {
    let mut t = term::stdout().unwrap();

    t.fg(term::color::GREEN).unwrap();
    write!(t, "hello, ").unwrap();

    t.fg(term::color::RED).unwrap();
    writeln!(t, "world!").unwrap();

    t.reset().unwrap();
}

on freebsd ends with the following error:

[root@fifo-bsd ~/term-test]# RUST_BACKTRACE=1 cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target/debug/term-test`
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /buildslave/rust-buildbot/slave/stable-dist-rustc-cross-host-linux/build/src/libcore/option.rs:323

this happens in the line (Deducted by 'cleverly ' sprinkeling the example with println!)

let mut t = term::stdout().unwrap();

panic with operation not supported by the terminal while libterm works fine

syntex project is port of rustc parser to
be able to use it with stable compiler.

It used term crate as replace of https://github.com/rust-lang/rust/tree/master/src/libterm

And we see difference between term and libterm, the same code from:
https://github.com/serde-rs/syntex/blob/master/syntex_errors/src/emitter.rs

cause panic if use term crate (0.4.5) and not panic and works as expected if use libterm.

See

https://github.com/keringar/syntex/commit/7ca0bb2e2dbae42d3983991787857730854336ef
serde-deprecated/syntex#121
rust-lang/rustfmt#1180
serde-deprecated/syntex#120

Any ideas why eshell handled in different ways in libterm and term?

Better Errors

Currently, we return strings as errors from the terminfo parsing functions. It would be nice to get an actual error type.

All Terminal methods leak memory on Windows

All WinConsole methods start by calling conout, which in turn calls kernel32::CreateFileA, this creates a new file handle that is not destroyed.

I've solved this locally by wrapping the handle in a struct that calls kernel32::CloseHandle on drop.

UMDH log:

+    4030 (  4030 -     0)      2 allocs    BackTrace333F5AF9
+       2 (     2 -     0)  BackTrace333F5AF9   allocations

    ntdll!LdrOpenImageFileOptionsKey+53
    ntdll!RtlAllocateHeap+1182
    KERNELBASE!CreateFileA+5D
    walk!term::win::conout+8D (...\contrib\term\src\win.rs, 79)
    walk!term::win::WinConsole<std::io::stdio::Stdout>::apply<std::io::stdio::Stdout>+47 (...\contrib\term\src\win.rs, 102)
    walk!term::win::{{impl}}::reset<std::io::stdio::Stdout>+5F (...\contrib\term\src\win.rs, 193)
    ...

+    2018 (  2018 -     0)      1 allocs    BackTrace333F5F39
+       1 (     1 -     0)  BackTrace333F5F39   allocations

    ntdll!LdrOpenImageFileOptionsKey+53
    ntdll!RtlAllocateHeap+1182
    KERNELBASE!CreateFileA+5D
    walk!term::win::conout+8D (...\contrib\term\src\win.rs, 79)
    walk!term::win::WinConsole<std::io::stdio::Stdout>::apply<std::io::stdio::Stdout>+47 (...\contrib\term\src\win.rs, 102)
    walk!term::win::{{impl}}::bg<std::io::stdio::Stdout>+5F (...\contrib\term\src\win.rs, 160)
    ...

Tagging @retep998.

Use `el` not `dl` to erase a line?

The docs say that delete_line will

Deletes the text from the cursor location to the end of the line.

According to https://books.google.com/books?id=GsUMLqtYI1UC&pg=PA115&lpg=PA115&dq=terminfo+dl&source=bl&ots=RpLCapUYS3&sig=4xJZMQuoegtf_9kaBSH-zSCf4_o&hl=en&sa=X&ved=0ahUKEwjaqPTZ-4HRAhVGs1QKHck5C4kQ6AEIMzAE#v=onepage&q=terminfo%20dl&f=false this sounds more like terminfo el than dl. That says that el is "erase to end of line" whereas dl "deletes lines in their entirity, with lines from below moving up to fill the gap"

I'm not sure if it's related but dl, ie ESC [0M doesn't seem to actually erase the line in iTerm2 3.0.10.

term::stdout() returns None unexpectedly

I tried running fselect whose first line is the following and it panics:

    let mut t = term::stdout().unwrap();

Environment:

  • Arch Linux, ncurses installed (6.1-3)
  • TERM: xterm-256color
  • Terminal emulator Tilix, GNOME Terminal

Notably if I set TERM to xterm or xterm-color, term::stdout() does not return None.

I don't have any trouble running other terminal command that I'm aware of. Presumably this a terminfo problem?

infocmp $TERM gives:

xterm-256color|xterm with 256 colors,
	am, bce, ccc, km, mc5i, mir, msgr, npc, xenl,
	colors#0x100, cols#80, it#8, lines#24, pairs#0x10000,
	acsc=``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,
	bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z, civis=\E[?25l,
	clear=\E[H\E[2J, cnorm=\E[?12l\E[?25h, cr=\r,
	csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=^H,
	cud=\E[%p1%dB, cud1=\n, cuf=\E[%p1%dC, cuf1=\E[C,
	cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\E[A,
	cvvis=\E[?12;25h, dch=\E[%p1%dP, dch1=\E[P, dim=\E[2m,
	dl=\E[%p1%dM, dl1=\E[M, ech=\E[%p1%dX, ed=\E[J, el=\E[K,
	el1=\E[1K, flash=\E[?5h$<100/>\E[?5l, home=\E[H,
	hpa=\E[%i%p1%dG, ht=^I, hts=\EH, ich=\E[%p1%d@,
	il=\E[%p1%dL, il1=\E[L, ind=\n, indn=\E[%p1%dS,
	initc=\E]4;%p1%d;rgb\:%p2%{255}%*%{1000}%/%2.2X/%p3%{255}%*%{1000}%/%2.2X/%p4%{255}%*%{1000}%/%2.2X\E\\,
	invis=\E[8m, is2=\E[!p\E[?3;4l\E[4l\E>, kDC=\E[3;2~,
	kEND=\E[1;2F, kHOM=\E[1;2H, kIC=\E[2;2~, kLFT=\E[1;2D,
	kNXT=\E[6;2~, kPRV=\E[5;2~, kRIT=\E[1;2C, kb2=\EOE, kbs=^H,
	kcbt=\E[Z, kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA,
	kdch1=\E[3~, kend=\EOF, kent=\EOM, kf1=\EOP, kf10=\E[21~,
	kf11=\E[23~, kf12=\E[24~, kf13=\E[1;2P, kf14=\E[1;2Q,
	kf15=\E[1;2R, kf16=\E[1;2S, kf17=\E[15;2~, kf18=\E[17;2~,
	kf19=\E[18;2~, kf2=\EOQ, kf20=\E[19;2~, kf21=\E[20;2~,
	kf22=\E[21;2~, kf23=\E[23;2~, kf24=\E[24;2~,
	kf25=\E[1;5P, kf26=\E[1;5Q, kf27=\E[1;5R, kf28=\E[1;5S,
	kf29=\E[15;5~, kf3=\EOR, kf30=\E[17;5~, kf31=\E[18;5~,
	kf32=\E[19;5~, kf33=\E[20;5~, kf34=\E[21;5~,
	kf35=\E[23;5~, kf36=\E[24;5~, kf37=\E[1;6P, kf38=\E[1;6Q,
	kf39=\E[1;6R, kf4=\EOS, kf40=\E[1;6S, kf41=\E[15;6~,
	kf42=\E[17;6~, kf43=\E[18;6~, kf44=\E[19;6~,
	kf45=\E[20;6~, kf46=\E[21;6~, kf47=\E[23;6~,
	kf48=\E[24;6~, kf49=\E[1;3P, kf5=\E[15~, kf50=\E[1;3Q,
	kf51=\E[1;3R, kf52=\E[1;3S, kf53=\E[15;3~, kf54=\E[17;3~,
	kf55=\E[18;3~, kf56=\E[19;3~, kf57=\E[20;3~,
	kf58=\E[21;3~, kf59=\E[23;3~, kf6=\E[17~, kf60=\E[24;3~,
	kf61=\E[1;4P, kf62=\E[1;4Q, kf63=\E[1;4R, kf7=\E[18~,
	kf8=\E[19~, kf9=\E[20~, khome=\EOH, kich1=\E[2~,
	kind=\E[1;2B, kmous=\E[<, knp=\E[6~, kpp=\E[5~,
	kri=\E[1;2A, mc0=\E[i, mc4=\E[4i, mc5=\E[5i, meml=\El,
	memu=\Em, oc=\E]104\007, op=\E[39;49m, rc=\E8,
	rep=%p1%c\E[%p2%{1}%-%db, rev=\E[7m, ri=\EM,
	rin=\E[%p1%dT, ritm=\E[23m, rmacs=\E(B, rmam=\E[?7l,
	rmcup=\E[?1049l\E[23;0;0t, rmir=\E[4l, rmkx=\E[?1l\E>,
	rmm=\E[?1034l, rmso=\E[27m, rmul=\E[24m,
	rs1=\Ec\E]104\007, rs2=\E[!p\E[?3;4l\E[4l\E>, sc=\E7,
	setab=\E[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m,
	setaf=\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m,
	sgr=%?%p9%t\E(0%e\E(B%;\E[0%?%p6%t;1%;%?%p5%t;2%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m,
	sgr0=\E(B\E[m, sitm=\E[3m, smacs=\E(0, smam=\E[?7h,
	smcup=\E[?1049h\E[22;0;0t, smir=\E[4h, smkx=\E[?1h\E=,
	smm=\E[?1034h, smso=\E[7m, smul=\E[4m, tbc=\E[3g,
	u6=\E[%i%d;%dR, u7=\E[6n, u8=\E[?%[;0123456789]c,
	u9=\E[c, vpa=\E[%i%p1%dd,

Doesn't work on FreeBSD

I cannot get this to work on FreeBSD. I'm not sure what it is expecting to find but I know FreeBSD does use a terminfo database which a comment in searcher.rs says it doesn't support. Is there a way to add support for the terminfo database, or else can I point it to some other files to convince it to work, or could there be some default fallback behaviour (assume VT100?) ?

Support parsing termcap

This is the correct way to support all platforms. This would fix #44 and would also allow us to correctly support mingw (msys) instead of hardcoding.

terminfo testing

Issue by cmr
Saturday Jun 01, 2013 at 00:01 GMT

For earlier discussion, see rust-lang/rust#6870

This issue was labelled with: A-testsuite, E-easy in the Rust repository


extra::terminfo testing needs to be more thorough and especially we need to distribute some terminfo entries in src/test and verify that all the expected capabilities are there and their correct values.

More shortcut functions in crate term

Issue by derekdreery
Sunday Nov 02, 2014 at 20:49 GMT

For earlier discussion, see rust-lang/rust#18548

This issue was labelled with: in the Rust repository


Just wondering if there are plans to add some more shortcut functionality in the term crate.

I.e. currently there is fg and bg functions to change color, but no functions for clearing part of the screen, changing cursor location etc.

All the machinery is already there (for reading terminfo etc), just need to implement the functions.

I don't know if this 'core' enough for the main lib, but it's very simple (a few short functions like the fg and bg ones) and avoids having to link to libcurses etc. At the moment I implement the stuff I need as a separate custom Trait, but it feels like it belongs in the term traits.

Don't know windows so don't know how complex terminal stuff works there.

Please relase a new version

The old version depends on dirs which is not maintained and causes transitive dependency on an old cfg_if leading to duplication. Releasing a new version would fix these issues.

WinConsole's tty check is inaccurate

When using WinConsole::new() it takes an arbitrary writer, but then it doesn't check whether that writer is a console, instead it just gets a handle to the current console buffer, whatever it is, and applies attributes to that, assuming that is also the writer.

This leads to silly situations where if someone passes a writer to WinConsole::new() that isn't the windows console but a pipe or any other sort of writer, or even a console framebuffer that isn't the active one, term will still set the attributes on the console frame buffer that was active at the time WinConsole::new() was called.

[LFM] Looking For Maintainer

So, I thought I'd have time to maintain this but then I got a job (where a large portion of said job is maintaining a bunch of OSS projects...). Unfortunately, that leaves me little time (or motivation) to maintain this project.

Better MSYS2 support

Currently only a very minimal set of operations are supported on mys2/cygwin, because it always falls back to msys_terminfo.

However, if it looked in the right place, it would be able to find and parse the correct terminfo: the problem is that it only searches unix-style paths (eg. /usr/share/terminfo) which are not valid for a native windows program.

On windows, it should convert these paths by calling cygpath -w /usr/share/terminfo before it tries to search them. With that modification the additional terminal features should just work.

Incorrectly claims dim/faint is not supported

I executed this code on my Ubuntu terminal:

t.attr(term::Attr::Dim);    // -> Ok(false)
(write!(t, "foo")).unwrap();
assert!(t.reset().unwrap());

"foo" looks completely normal and when piping the output into a file it looks like that: foo^[(B^[[0m. However, my terminal supports dim/faint mode, since executing

println!("\x1b[2mfoo\x1b[0m");

has the desired output (a dim "foo"). Apparently this also happens with "Terminator" on Arch Linux (see LukasKalbertodt/term-painter#12).

Release for 0.3

Any plans to release 0.3 soon? It fixes an issue that I'm experience using iron/logger, and it would be great to be able to point at an official release instead of the git url.

iron/logger#72

Thanks for all the hard work ๐Ÿ˜„

Write plain text when running under a start/stop daemon like systemd ?

Is there a way to make this work with systemd.
Wen I say work I mean just output to the journal on Linux like println! or logging does.

Currently term::stdout() return None when running as a daemon.
I wondered if there were a nicer way on writing without having to check for none all the time.

Thanks

Support for getting terminal width & height

Getting the terminal width and height is something you cannot do presently with the Terminal trait. It prevents implementation of something like termbox on top of Terminal trait.

The linux implementation looks something like (from termbox)

    struct winsize sz;
    memset(&sz, 0, sizeof(sz));

    ioctl(inout, TIOCGWINSZ, &sz);

    termw = sz.ws_col;
    termh = sz.ws_row;

whilst in windows the relevant function is kernel32::GetConsoleScreenBufferInfo

Color with macros ?

I was wondering if there was a way to use macros to color the terminal output.

Instead of

let mut t = term::stdout().unwrap();

t.fg(term::color::GREEN).unwrap();
write!(t, "hello, ").unwrap();

You could write something like this:

println!(green!("Hello"));

If it is possible, it would be really nice to have as a more lightweight alternative to the existing method :)

kernel32-sys has "*" version dependency of winapi

I cannot build term from crates.io, because i end up with 0.1 of winapi for term and 0.2 of winapi of kernel32-sys. This causes incompatible types when kernel32-sys functions return a type that is different in winapi 0.2

Check isatty == false before coloring

Hi!

I've found this library as an excellent solution to colorize the logging output. However, when the stdout/stderr is redirected somewhere else (./a.out > log.txt for example) the final output is still mangled with terminal special characters as an opposite expected behavior.

It's a common practice in Unix to check isatty function before trying to colorize, see man for more. Moreover the isatty function is associated with terminal as like as this crate, so it may be useful to add it.

I can implement this functionality if you agree. Thoughts?

`Terminal` should probably buffer

It would be good if the terminal types could have built-in buffering, preferably line-buffering. Currently, every write call in a formatter directly causes a syscall, slowing terminal output down. Additionally, there's no need to flush after every color code on ANSI terminals, it would be more efficient to output them together with the actual text.

In slog-rs/slog#125 you can see that it causes a more than 2x speedup to simply put a LineBuffer around the terminal. On Windows, this would also need to include a flush before the terminal properties are changed to output in a different color.

How to store and pass around `Terminal` of any type.

Hi,

I wonder how to store and pass around Terminal of any type: no matter if it logs to stdout, stder, on Windows, or elsewhere. Like Box<Terminal>, that because of type Output seems currently impossible. I wish I could have Box<Terminal<Output=Write>> or something like that.

Am I missing something, and if not, could some solution for this be provided?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.