1
0
Fork 0
mirror of https://github.com/lise-henry/crowbook synced 2024-05-12 18:56:10 +02:00

Start replacing crowbook-int in lib

This commit is contained in:
Elisabeth Henry 2023-08-19 02:37:24 +02:00
parent 0ff24f94f4
commit 682cc039a3
4 changed files with 26 additions and 26 deletions

11
lang/lib/en.yml Normal file
View File

@ -0,0 +1,11 @@
ui:
rendering: Rendering...
waiting: waiting...
error:
no_string: "%{s} is not a string"
no_string_vector: "%{s} is not a string vector"
no_path: "%{s} is not a path"
no_bool: "%{s} is not a boolean"
no_char: "%{s} is not a char"
no_i32: "%{s} is not an i32"
no_f32: "%{s} is not a f32"

View File

@ -21,6 +21,7 @@
use crate::book::{Book, Crowbar, CrowbarState};
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
use rust_i18n::t;
use std::sync::Arc;
use std::time::Duration;
@ -79,19 +80,7 @@ impl Book<'_> {
.add(ProgressBar::new_spinner());
b.enable_steady_tick(Duration::from_millis(200));
self.bars.mainbar = Some(b);
// let sty = ProgressStyle::default_spinner()
// .tick_chars("πŸ•›πŸ•πŸ•‘πŸ•’πŸ•“πŸ•”πŸ•”πŸ••πŸ•–πŸ•—πŸ•˜πŸ•˜πŸ•™πŸ•šV")
// .tick_chars("/|\\-V")
// .template("{spinner:.dim.bold.yellow} {prefix} {wide_msg}");
self.bar_set_style(Crowbar::Main, CrowbarState::Running);
// self.bars.guard = Some(thread::spawn(move || {
// if let Err(_) = multibar.join() {
// error!(
// "{}",
// lformat!("could not display fancy UI, try running crowbook with --no-fancy")
// );
// }
// }));
}
/// Sets a finished message to the progress bar, if it is set
@ -148,12 +137,12 @@ impl Book<'_> {
pub fn add_spinner_to_multibar(&mut self, key: &str) -> usize {
if let Some(ref multibar) = self.bars.multibar {
if let Some(ref mainbar) = self.bars.mainbar {
mainbar.set_message(lformat!("Rendering..."));
mainbar.set_message(t!("ui.rendering"));
}
let bar = multibar.add(ProgressBar::new_spinner());
bar.enable_steady_tick(Duration::from_millis(200));
bar.set_message(lformat!("waiting..."));
bar.set_message(t!("ui.waiting"));
bar.set_prefix(format!("{key}:"));
let i = self.bars.spinners.len();
self.bars.spinners.push(bar);

View File

@ -1,3 +1,5 @@
use rust_i18n::t;
use crate::error::{Error, Result, Source};
/// Structure for storing a book option
@ -50,7 +52,7 @@ impl BookOption {
BookOption::String(ref s) => Ok(s),
_ => Err(Error::book_option(
Source::empty(),
lformat!("{:?} is not a string", self),
t!("error.no_string", s = format!("{:?}", self)),
)),
}
}
@ -61,7 +63,7 @@ impl BookOption {
BookOption::StringVec(ref v) => Ok(v),
_ => Err(Error::book_option(
Source::empty(),
lformat!("{:?} is not a string vector", self),
t!("error.no_string_vector", s = format!("{:?}", self)),
)),
}
}
@ -72,7 +74,7 @@ impl BookOption {
BookOption::Path(ref s) => Ok(s),
_ => Err(Error::book_option(
Source::empty(),
lformat!("{:?} is not a path", self),
t!("error.no_path", s = format!("{:?}", self)),
)),
}
}
@ -83,7 +85,7 @@ impl BookOption {
BookOption::Bool(b) => Ok(b),
_ => Err(Error::book_option(
Source::empty(),
lformat!("{:?} is not a bool", self),
t!("error.no_bool", s = format!("{:?}", self)),
)),
}
}
@ -94,7 +96,7 @@ impl BookOption {
BookOption::Char(c) => Ok(c),
_ => Err(Error::book_option(
Source::empty(),
lformat!("{:?} is not a char", self),
t!("error.no_char", s = format!("{:?}", self)),
)),
}
}
@ -105,7 +107,7 @@ impl BookOption {
BookOption::Int(i) => Ok(i),
_ => Err(Error::book_option(
Source::empty(),
lformat!("{:?} is not an i32", self),
t!("error.no_i32", s = format!("{:?}", self)),
)),
}
}
@ -116,7 +118,7 @@ impl BookOption {
BookOption::Float(f) => Ok(f),
_ => Err(Error::book_option(
Source::empty(),
lformat!("{:?} is not a f32", self),
t!("error.no_f32", s = format!("{:?}", self)),
)),
}
}

View File

@ -1,4 +1,4 @@
// Copyright (C) 2016, 2017, 2018 Γ‰lisabeth HENRY.
// Copyright (C) 2016-2023 Γ‰lisabeth HENRY.
//
// This file is part of Crowbook.
//
@ -109,10 +109,6 @@ extern crate log;
#[macro_use]
extern crate lazy_static;
#[cfg(feature = "proofread")]
#[macro_use]
extern crate serde_derive;
pub use book::Book;
pub use book_renderer::BookRenderer;
pub use bookoption::BookOption;
@ -127,6 +123,8 @@ pub use stats::Stats;
pub use token::Data;
pub use token::Token;
rust_i18n::i18n!("lang/lib", fallback="en");
#[macro_use]
#[doc(hidden)]
mod localize_macros;