Skip to content

Commit

Permalink
Implemented download prompt.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrueger committed Jan 28, 2025
1 parent 32cdefc commit ac2420b
Show file tree
Hide file tree
Showing 24 changed files with 321 additions and 135 deletions.
5 changes: 3 additions & 2 deletions crates/icy_board/src/menu_runner/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ impl PcbBoardCommand {
}
}
if settings.ask_xfer_protocol {
let protocol = self.state.ask_protocols("N".to_string()).await?;
let protocol = self.state.ask_protocols("N").await?;
self.state.new_line().await?;
if !protocol.is_empty() {
new_user.protocol = protocol;
} else {
Expand Down Expand Up @@ -656,7 +657,7 @@ impl PcbBoardCommand {
self.state.new_line().await?;
let date_formats = self.state.get_board().await.languages.date_formats.clone();

self.state.set_color(TerminalTarget::Both, IcbColor::Dos(11)).await?;
self.state.set_color(TerminalTarget::Both, IcbColor::dos_cyan()).await?;
let mut preview = String::new();
for (i, (disp_fmt, fmt)) in date_formats.iter().enumerate() {
if fmt == cur_format {
Expand Down
2 changes: 1 addition & 1 deletion crates/icy_board_engine/src/data/ICBTEXT.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1848,7 +1848,7 @@ style = "White"
text = "Output File Name"
style = "Red"

[BatchDownloadTime]
[_BatchDownloadTime]
text = "Batch Download Time:~"
style = "Yellow"

Expand Down
37 changes: 37 additions & 0 deletions crates/icy_board_engine/src/icy_board/icb_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,43 @@ pub enum IcbColor {
IcyEngine(Color),
}

impl IcbColor {
pub fn dos_black() -> Self {
IcbColor::Dos(0x00)
}
pub fn dos_blue() -> Self {
IcbColor::Dos(0x00)
}

pub fn dos_light_blue() -> Self {
IcbColor::Dos(0x09)
}

pub fn dos_light_green() -> Self {
IcbColor::Dos(0x0A)
}

pub fn dos_cyan() -> Self {
IcbColor::Dos(0x0B)
}

pub fn dos_light_red() -> Self {
IcbColor::Dos(0x0C)
}

pub fn dos_magenta() -> Self {
IcbColor::Dos(0x0D)
}

pub fn dos_yellow() -> Self {
IcbColor::Dos(0x0E)
}

pub fn dos_white() -> Self {
IcbColor::Dos(0x0F)
}
}

impl From<u8> for IcbColor {
fn from(color: u8) -> Self {
IcbColor::Dos(color)
Expand Down
16 changes: 8 additions & 8 deletions crates/icy_board_engine/src/icy_board/icb_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ pub enum IceText {
/// `Output File Name`
OutputFileName = 479,
/// `Batch Download Time:~`
BatchDownloadTime = 480,
_BatchDownloadTime = 480,
/// `Batch Download Size:~`
BatchDownloadSize = 481,
/// `Batch Protocol Type: ~`
Expand Down Expand Up @@ -1633,13 +1633,13 @@ impl IcbTextStyle {
pub fn to_color(&self) -> IcbColor {
match self {
IcbTextStyle::Plain => IcbColor::None,
IcbTextStyle::Red => IcbColor::Dos(12),
IcbTextStyle::Green => IcbColor::Dos(10),
IcbTextStyle::Yellow => IcbColor::Dos(14),
IcbTextStyle::Blue => IcbColor::Dos(9),
IcbTextStyle::Purple => IcbColor::Dos(13),
IcbTextStyle::Cyan => IcbColor::Dos(11),
IcbTextStyle::White => IcbColor::Dos(15),
IcbTextStyle::Red => IcbColor::dos_light_red(),
IcbTextStyle::Green => IcbColor::dos_light_green(),
IcbTextStyle::Yellow => IcbColor::dos_yellow(),
IcbTextStyle::Blue => IcbColor::dos_light_blue(),
IcbTextStyle::Purple => IcbColor::dos_magenta(),
IcbTextStyle::Cyan => IcbColor::dos_cyan(),
IcbTextStyle::White => IcbColor::dos_white(),
}
}

Expand Down
13 changes: 1 addition & 12 deletions crates/icy_board_engine/src/icy_board/state/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,6 @@ pub mod display_flags {
pub const NOTBLANK: i32 = 0x02000; // same as 'AUTO'
}

pub mod pcb_colors {
use crate::icy_board::icb_config::IcbColor;

pub const BLUE: IcbColor = IcbColor::Dos(9);
pub const GREEN: IcbColor = IcbColor::Dos(10);
pub const CYAN: IcbColor = IcbColor::Dos(11);
pub const RED: IcbColor = IcbColor::Dos(12);
pub const MAGENTA: IcbColor = IcbColor::Dos(13);
pub const YELLOW: IcbColor = IcbColor::Dos(14);
pub const WHITE: IcbColor = IcbColor::Dos(15);
}
const TXT_STOPCHAR: char = '_';

lazy_static::lazy_static! {
Expand Down Expand Up @@ -233,7 +222,7 @@ impl IcyBoardState {
let Ok(content) = fs::read(resolved_name) else {
if display_error {
self.bell().await?;
self.set_color(TerminalTarget::Both, pcb_colors::RED).await?;
self.set_color(TerminalTarget::Both, IcbColor::dos_light_red()).await?;
self.print(TerminalTarget::Both, &format!("\r\n({}) is missing!\r\n\r\n", file_name.as_ref().display()))
.await?;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/icy_board_engine/src/icy_board/state/menu_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl IcyBoardState {
}
CommandType::FlagFiles => {
// FLAG
self.flag_files().await?;
self.flag_files_cmd(false).await?;
}
CommandType::EnterMessage => {
// E
Expand Down
45 changes: 14 additions & 31 deletions crates/icy_board_engine/src/icy_board/state/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
collections::{HashMap, HashSet, VecDeque},
collections::{HashMap, VecDeque},
fmt::Alignment,
fs,
path::{Path, PathBuf},
Expand Down Expand Up @@ -102,35 +102,16 @@ impl Default for DisplayOptions {
pub struct TransferStatistics {
pub downloaded_files: usize,
pub downloaded_bytes: usize,
pub downloaded_cps: usize,

pub uploaded_files: usize,
pub uploaded_bytes: usize,

pub dl_transfer_time: usize,
pub ul_transfer_time: usize,
pub uploaded_cps: usize,
}

impl TransferStatistics {
pub fn get_cps_download(&self) -> usize {
if self.dl_transfer_time == 0 {
return 0;
}
self.downloaded_bytes / self.dl_transfer_time
}

pub fn get_cps_upload(&self) -> usize {
if self.ul_transfer_time == 0 {
return 0;
}
self.uploaded_bytes / self.ul_transfer_time
}

pub fn get_cps_both(&self) -> usize {
let total_time = self.dl_transfer_time + self.ul_transfer_time;
if total_time == 0 {
return 0;
}
// actually correct - it's not the average, but the accumlated csp
(self.downloaded_bytes + self.uploaded_bytes) / total_time
(self.downloaded_cps + self.uploaded_cps) / 2
}
}

Expand Down Expand Up @@ -205,7 +186,7 @@ pub struct Session {

// The maximum number of files in flagged_files
pub batch_limit: usize,
pub flagged_files: HashSet<PathBuf>,
pub flagged_files: Vec<PathBuf>,
}

impl Session {
Expand Down Expand Up @@ -250,7 +231,7 @@ impl Session {
saved_color: IcbColor::Dos(7),

sysop_name: "SYSOP".to_string(),
flagged_files: HashSet::new(),
flagged_files: Vec::new(),
emsi: None,
paged_sysop: false,
bytes_remaining: 0,
Expand Down Expand Up @@ -1027,7 +1008,7 @@ impl IcyBoardState {
return Ok(());
}
if ch.source == KeySource::Sysop {
self.set_color(TerminalTarget::Both, IcbColor::Dos(10)).await?;
self.set_color(TerminalTarget::Both, IcbColor::dos_light_green()).await?;
} else {
self.reset_color(TerminalTarget::Both).await?;
}
Expand Down Expand Up @@ -1377,7 +1358,9 @@ impl IcyBoardState {
"FIRSTU" => {
result = self.session.get_first_name().to_uppercase();
}
"FNUM" => {}
"FNUM" => {
result = (self.session.flagged_files.len() + 1).to_string();
}
"FREESPACE" => {}
"GFXMODE" => {
result = match self.session.disp_options.grapics_mode {
Expand Down Expand Up @@ -1478,7 +1461,7 @@ impl IcyBoardState {
return None;
}
"PROLTR" | "PRODESC" | "PWXDATE" | "PWXDAYS" | "QOFF" | "QON" | "RATIOBYTES" | "RATIOFILES" => {}
"RCPS" => result = self.transfer_statistics.get_cps_upload().to_string(),
"RCPS" => result = self.transfer_statistics.uploaded_cps.to_string(),
"RBYTES" => result = self.transfer_statistics.uploaded_bytes.to_string(),
"RFILES" => result = self.transfer_statistics.uploaded_files.to_string(),
"REAL" => {
Expand All @@ -1491,7 +1474,7 @@ impl IcyBoardState {
result = user.security_level.to_string()
}
}
"SCPS" => result = self.transfer_statistics.get_cps_download().to_string(),
"SCPS" => result = self.transfer_statistics.downloaded_cps.to_string(),
"SBYTES" => result = self.transfer_statistics.downloaded_bytes.to_string(),
"SFILES" => result = self.transfer_statistics.downloaded_files.to_string(),
"SYSDATE" => {
Expand Down Expand Up @@ -1799,7 +1782,7 @@ impl IcyBoardState {
let pos = self.user_screen.caret.get_position();
self.set_activity(NodeStatus::NodeMessage).await;
self.new_line().await?;
self.set_color(TerminalTarget::Both, IcbColor::Dos(15)).await?;
self.set_color(TerminalTarget::Both, IcbColor::dos_white()).await?;
self.println(TerminalTarget::Both, &"Broadcast:").await?;
self.println(TerminalTarget::Both, &msg).await?;
self.bell().await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ impl IcyBoardState {
}
}
if settings.ask_xfer_protocol {
let protocol = self.ask_protocols("N".to_string()).await?;
let protocol = self.ask_protocols("N").await?;
if !protocol.is_empty() {
new_user.protocol = protocol;
} else {
Expand Down Expand Up @@ -610,7 +610,7 @@ impl IcyBoardState {
self.new_line().await?;
let date_formats = self.get_board().await.languages.date_formats.clone();

self.set_color(TerminalTarget::Both, IcbColor::Dos(11)).await?;
self.set_color(TerminalTarget::Both, IcbColor::dos_cyan()).await?;
let mut preview = String::new();
for (i, (disp_fmt, fmt)) in date_formats.iter().enumerate() {
if fmt == cur_format {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl EditState {
let line: usize = self.read_line_number(IceText::DeleteLineNumber, state).await?;
if line > 0 && (line as usize - 1) < self.msg.len() {
self.print_divider(state).await?;
state.set_color(TerminalTarget::Both, IcbColor::Dos(11)).await?;
state.set_color(TerminalTarget::Both, IcbColor::dos_cyan()).await?;
state.print(TerminalTarget::Both, &format!("{}: ", line)).await?;
state.reset_color(TerminalTarget::Both).await?;
state.println(TerminalTarget::Both, &self.msg[line - 1]).await?;
Expand Down Expand Up @@ -194,15 +194,15 @@ impl EditState {

let to_part = format!("{}{}", to_txt, self.to);
let subj_part = format!("{}{} {}", subj_txt, self.subj, Local::now().format("%H:%M"));
state.set_color(TerminalTarget::Both, IcbColor::Dos(14)).await?;
state.set_color(TerminalTarget::Both, IcbColor::dos_yellow()).await?;
state.println(TerminalTarget::Both, &format!("{:<38}{:<38}", to_part, subj_part)).await?;
self.print_divider(state).await?;

Ok(())
}

async fn print_divider(&mut self, state: &mut IcyBoardState) -> Res<()> {
state.set_color(TerminalTarget::Both, IcbColor::Dos(11)).await?;
state.set_color(TerminalTarget::Both, IcbColor::dos_cyan()).await?;
state.println(TerminalTarget::Both, &str::repeat("-", 79)).await?;
state.reset_color(TerminalTarget::Both).await?;
Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl IcyBoardState {
self.session.push_tokens(&input);
match self.session.tokens.pop_front().unwrap_or_default().to_ascii_uppercase().as_str() {
"F" | "FL" | "FLA" | "FLAG" => {
self.flag_files().await?;
self.flag_files_cmd(false).await?;
}
"V" | "S" => {
self.view_file().await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl IcyBoardState {
.await?;
self.println(TerminalTarget::Both, " Length Date Time Name").await?;
self.println(TerminalTarget::Both, " ======== ========== ===== ======").await?;
self.set_color(TerminalTarget::Both, IcbColor::Dos(11)).await?;
self.set_color(TerminalTarget::Both, IcbColor::dos_cyan()).await?;
for info in &file_content {
if self.session.disp_options.abort_printout {
break;
Expand All @@ -90,11 +90,11 @@ impl IcyBoardState {
self.println(TerminalTarget::Both, &info.name).await?;
len += info.size;
}
self.set_color(TerminalTarget::Both, IcbColor::Dos(14)).await?;
self.set_color(TerminalTarget::Both, IcbColor::dos_yellow()).await?;
self.set_color(TerminalTarget::Both, colors.file_head.clone()).await?;
self.println(TerminalTarget::Both, "--------- ------").await?;
self.set_color(TerminalTarget::Both, colors.file_size).await?;
self.set_color(TerminalTarget::Both, IcbColor::Dos(15)).await?;
self.set_color(TerminalTarget::Both, IcbColor::dos_white()).await?;
self.println(
TerminalTarget::Both,
&format!("{:>9} {} files", humanize_bytes_decimal!(len).to_string(), file_content.len()),
Expand Down
Loading

0 comments on commit ac2420b

Please sign in to comment.