Skip to content

Commit 32a7b3f

Browse files
committed
cli: add file
1 parent 704fecc commit 32a7b3f

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ansi2/Cargo.toml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ansi2/src/canvas.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::collections::VecDeque;
33
use crate::{
44
ans::min_distance,
55
color::{AnsiColor, Color8},
6-
lex::{parse_ansi, Sgr, Token},
6+
lex::{Sgr, Token, parse_ansi},
77
node::Node,
88
};
99

@@ -87,7 +87,7 @@ impl Canvas {
8787
let mut color_r = (0, 0);
8888
let mut bold_r = (0, 0);
8989
let mut blink_r = (0, 0);
90-
let mut text_r = (0, 0);
90+
// let mut text_r = (0, 0);
9191
let mut dim_r = (0, 0);
9292
let mut italic_r = (0, 0);
9393
let mut underline_r = (0, 0);
@@ -137,7 +137,7 @@ impl Canvas {
137137
}
138138

139139
Sgr::Char(c) => {
140-
text_r = range;
140+
// text_r = range;
141141
let node = Node {
142142
text: c.into(),
143143
bg_color: cur_bg_c,
@@ -154,7 +154,7 @@ impl Canvas {
154154
color_r,
155155
bold_r,
156156
blink_r,
157-
text_r,
157+
text_r: range,
158158
dim_r,
159159
italic_r,
160160
underline_r,

ansi2/src/main.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use ansi2::ans::to_ans;
22
use ansi2::image::image_to_ans;
33
use ansi2::{css::Mode, theme::Theme};
44
use ansi2::{html::to_html, svg::to_svg, text::to_text};
5-
use base64::prelude::BASE64_STANDARD;
65
use base64::Engine;
7-
use clap::{command, Parser, ValueEnum};
6+
use base64::prelude::BASE64_STANDARD;
7+
use clap::{Parser, ValueEnum, command};
88
use std::path::Path;
99
use std::{fs::read, io::Read};
1010

@@ -47,6 +47,9 @@ struct Args {
4747

4848
#[arg(short, long, default_value_t = false)]
4949
sourcemap: bool,
50+
51+
#[clap()]
52+
file: Option<String>,
5053
}
5154

5255
fn process_input(buf: Vec<u8>) -> String {
@@ -73,14 +76,20 @@ fn main() {
7376
font_size,
7477
length_adjust,
7578
sourcemap,
79+
file,
7680
} = args;
7781
let format = format.unwrap_or(Format::Svg);
7882
let theme = theme.unwrap_or(Theme::Vscode);
7983

80-
let mut buf = Vec::new();
81-
std::io::stdin()
82-
.read_to_end(&mut buf)
83-
.expect("can't read string from stdin");
84+
let buf = if let Some(file) = file {
85+
std::fs::read(file).expect("can't read string from file")
86+
} else {
87+
let mut v = Vec::new();
88+
std::io::stdin()
89+
.read_to_end(&mut v)
90+
.expect("can't read string from stdin");
91+
v
92+
};
8493

8594
let s = process_input(buf);
8695
let base64 = font.map(|font_url| {

0 commit comments

Comments
 (0)