Logging for text that should stay in the same place in a console.

Overview

console_static_text

Crate for logging text that should stay in the same place in a console. This measures words to handle wrapping and has some console resizing support. Example use might be for displaying progress bars or rendering selections.

Example use with the console crate:

use console_static_text::ConsoleSize;
use console_static_text::ConsoleStaticText;

let mut static_text = ConsoleStaticText::new(|| {
  let size = console::Term::stderr().size();
  ConsoleSize {
    rows: Some(size.0),
    cols: Some(size.1),
  }
});

static_text.eprint("initial\ntext");
std::thread::sleep_ms(1000);

// will clear the previous text and put this new text
static_text.eprint("new text");
std::thread::sleep_ms(1000);

// or get and output the text manually
if let Some(text) = static_text.render("new text") {
  eprint!("{}", text);
  std::thread::sleep_ms(1000);
}

// clear out the previous text
static_text.eprint_clear();

Hanging indentation

To get hanging indentation, you can use the lower level "items" api.

static_text.eprint_items(vec![
  TextItem::Text(Cow::Borrowed("Some non-hanging text.")),
  TextItem::HangingText {
    text: Cow::Borrowed("some long text that will wrap at a certain width"),
    indent: 4,
  },
].iter());

This is useful when implementing something like a selection UI where you want text to wrap with hanging indentation.

"sized" feature

By default, this crate encourages you to use your own functionality for getting the console size since you'll likely already have a dependency that does that, but if not, then you can use the sized Cargo.toml feature.

[dependencies]
console_static_text = { version = "...", features = ["sized"] }

Then you can use the new_sized function, which will get the console size automatically:

let mut static_text = ConsoleStaticText::new_sized();

static_text.eprint("initial\ntext");
std::thread::sleep_ms(1000);

static_text.eprint("next text");
You might also like...
✨ sleek typing tui with visualized results and historical logging
✨ sleek typing tui with visualized results and historical logging

thokr ✨ sleek typing tui with visualized results and historical logging Usage For detailed usage run thokr -h. thokr 0.4.1 sleek typing tui with visua

A super simple but lightweight logging library that tries to capture the most important (status) information.

Hackerlog A super simple but lightweight logging library that tries to capture the most important (status) information. The following is supported: Lo

A beautiful, tiny traceback and logging library supporting #![no_std] rust.

breadcrumbs Breadcrumbs is a beautiful, tiny traceback and logging library for Rust that offers seamless integration with #![no_std], multi-threading

An extremely high performance logging system for clients (iOS, Android, Desktop), written in Rust.

Pinenut Log 中文文档 ・ English An extremely high performance logging system for clients (iOS, Android, Desktop), written in Rust. Overview Compression Pin

A versatile and extensible logging implementation.

Logforth Project Overview A versatile and extensible logging implementation. Usage Add the dependencies to your Cargo.toml with: cargo add log cargo a

Console progress bar for Rust
Console progress bar for Rust

Terminal progress bar for Rust Console progress bar for Rust Inspired from pb, support and tested on MacOS, Linux and Windows Documentation Examples s

🌈 Brings back colour console to Win64 for Garry's Mod SRCDS
🌈 Brings back colour console to Win64 for Garry's Mod SRCDS

🌈 gmsv_concolormsg This module for Garry's Mod fixes x86-64 Windows 64-bit SRCDS not displaying colours. Why does it do that? Who knows! But it's eas

Simple console input macros with the goal of being implemented in the standard library.

Simple console input macros with the goal of being implemented in the standard library.

Tldr - 📚 Collaborative cheatsheets for console commands
Tldr - 📚 Collaborative cheatsheets for console commands

What is tldr-pages? The tldr-pages project is a collection of community-maintained help pages for command-line tools, that aims to be a simpler, more

Comments
  • Perf - Handle someone creating thousands of text items

    Perf - Handle someone creating thousands of text items

    This crate should not become less performant when someone creates a lot of text items. Essentially instead of evaluating text items bottom down, it should instead evaluate them bottom up and stop once it fills the console height.

    enhancement 
    opened by dsherret 0
Owner
David Sherret
David Sherret
Work out how far apart things should be (very quickly)

Kern determiner Work out how far apart things should be (very quickly) kerndeterminer is a Rust-based library for determining a kern value between two

Simon Cozens 10 Oct 29, 2022
Need a powerful and simple library to work with arithmetic progressions in Rust? You should definitively try out ariprog!

Ariprog I had a test (03/2024) on arithmetic progressions, so I decided to create a library to study math. Taking advantage of the fact that I was stu

Kauê Fraga Rodrigues 4 Mar 19, 2024
This repo contains crates that are used to create the micro services and keep shared code in a common place.

MyEmma Helper Crates This repo contains crates that can are reused over different services. These crate are used in projects at MyEmma. But these crat

MyEmma 1 Jan 14, 2022
🧖🏻‍♀️ Symlink your Steam screenshots to a sensible place

lnshot ????‍♀️ Symlink your Steam games' screenshot directories into your Pictures folder About This is a little utility to work around a bugbear of m

Jessica Stokes 23 Jan 31, 2023
ddi is a wrapper for dd. It takes all the same arguments, and all it really does is call dd in the background

ddi A safer dd Introduction If you ever used dd, the GNU coreutil that lets you copy data from one file to another, then you may have encountered a ty

Tomás Ralph 80 Sep 8, 2022
Switch windows of same app with alt + ` on windows pc.

Windows Switcher Switch windows of same app with alt + ` on windows pc. 250k single file executable downloaded from Github Release. No installation re

null 172 Dec 10, 2022
Same procedure as every year… right?

Advent of Code 2022 solutions What this repository is This repository contains solutions to Eric Wastls Advent of Code 2022. Thank you, Eric! While th

Patrick 3 Dec 15, 2022
Bruteforce connecting to a specific Sea of Thieves server. Useful if you want to be in the same server as your friends.

SoT Server Finder Find which Sea of Thieves server you're connected to. Useful if you want to be in the same server as your friends. Setup Download so

Martin 4 Mar 19, 2023
An implementation of Piet's text interface using cosmic-text

piet-cosmic-text Implements piet's Text interface using the cosmic-text crate. License piet-cosmic-text is free software: you can redistribute it and/

John Nunley 7 Mar 12, 2023
Application microframework with command-line option parsing, configuration, error handling, logging, and shell interactions

Abscissa is a microframework for building Rust applications (either CLI tools or network/web services), aiming to provide a large number of features w

iqlusion 524 Dec 26, 2022