#matrix #display #command-line #separator #unicode #pretty #character

matrix_display

一个用于在命令行中以美观的Unicode分隔符显示矩阵的库

11个版本 (1个稳定版)

1.0.0 2019年5月12日
0.9.0 2018年3月6日
0.8.0 2017年7月22日
0.5.0 2017年3月29日

#881文本处理

每月下载量 33次
3 crates 使用

MIT 许可证

8.5MB
752 代码行

包含 (WOFF字体, 94KB) docs/SourceSerifPro-Bold.ttf.woff, (WOFF字体, 90KB) docs/FiraSans-Medium.woff, (WOFF字体, 92KB) docs/FiraSans-Regular.woff, (WOFF字体, 89KB) docs/SourceSerifPro-Regular.ttf.woff, (WOFF字体, 56KB) docs/SourceCodePro-Regular.woff, (WOFF字体, 56KB) docs/SourceCodePro-Semibold.woff 和更多.

构建状态 覆盖率状态 Matrix Display

一个简单的Rust库,用于在Rust中可视化2D矩阵。

  • 支持使用AnsiTerm的256种终端颜色
  • 支持多种Unicode框字符集(普通、复古、细、圆角、粗、双倍)

文档

点击此处访问文档

构建

运行

  • cargorun --examplechess
  • cargorun --example 2048
  • cargorun --example调色板

示例:可视化棋盘

extern crate matrix_display;
use matrix_display::*;

fn main() {
    let format = Format::new(7, 3);
	let board = vec!['', '', '', '', '', '', '', '',
	                 '', '', '', '', '', '', '', '',
					 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
                     ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
					 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
					 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
					 '', '', '', '', '', '', '', '',
					 '', '', '', '', '', '', '', '']
        .iter()
        .enumerate()
		.map(|(i, x)| {
            let ansi_fg = 33;
			let mut ansi_bg = 0;
		    if i % 2 + (i / 8) % 2 == 1 {
			    ansi_bg = 7;
			}
		    cell::Cell::new(x.clone(), ansi_fg, ansi_bg)
			})
        .collect::<Vec<_>>();
    let data = matrix::Matrix::new(8, board);
    let display = MatrixDisplay::new(format, data);
	display.cell_at_cursor_position((13, 6)).color.bg = 10;
    display.print(&mut std::io::stdout(), &style::BordersStyle::None);
}

alt tag

查看游戏的运行版本,请见 chess-rs

示例:可视化2048游戏

extern crate matrix_display;
use matrix_display::*;

fn main() {
    let format = Format::new(7, 3);
    let colour_theme = vec![247, 78, 222, 220, 214, 208, 202, 196, 162, 160, 126, 90, 88, 54, 53, 52];
    let board = (0..16)
        .map(|x| {
            cell::Cell::new(2_f64.powi(x + 1),
                      7,
                      *colour_theme.get(x as usize).unwrap() as u8)
        })
        .collect::<Vec<_>>();
    let data = matrix::Matrix::new(4, board);
    let display = MatrixDisplay::new(format, data);
    display.print(&mut std::io::stdout(), &style::BordersStyle::Thick);
}

alt tag

查看游戏的运行版本,请见 2048-rs

示例:可视化256色调色板

extern crate matrix_display;
use matrix_display::*;

fn main() {
    let format = Format::new(5, 1);
    let board = (0..256)
        .map(|x| cell::Cell::new(x, 0, x as u8))
        .collect::<Vec<_>>();
    let data = matrix::Matrix::new(8, board);
    let display = MatrixDisplay::new(format, data);
    display.print(&mut std::io::stdout(), &style::BordersStyle::Thin);

alt tag

查看自包含实现,请见 palette-rs

待办事项

  • 利用fdehau/tui-rs避免在每一帧重绘整个屏幕
  • 应有助于解决 snake-rs 的性能问题,我的蛇实现。

依赖项

~9.5MB
~117K SLoC