Skip to content
Snippets Groups Projects
Commit 1115bd2b authored by Stephen D's avatar Stephen D
Browse files

add station callsign

parent 7411dfa7
No related branches found
No related tags found
1 merge request!1add station callsign
Pipeline #257 passed
use crate::qso::Qso;
use crate::station::Station;
use crate::traits::TuiValue;
use chrono::Utc;
use serde::{Deserialize, Serialize};
......@@ -10,6 +11,8 @@ const MAX_COLUMN_WIDTH: usize = 40;
#[derive(Serialize, Deserialize, Default)]
pub struct State {
#[serde(default)]
station: Station,
qsos: Vec<Qso>,
}
......@@ -58,12 +61,13 @@ impl App {
pub fn run(&mut self) {
loop {
self.render_table();
println!("\t[A] Add QSO\t[E] Edit QSO\t[D] Del QSO\t[Q] Quit");
println!(
"\t[A] Add QSO\t[E] Edit QSO\t[D] Del QSO\t[C] Edit Station Callsign\t[Q] Quit"
);
// Wish this had unicode support ):
let c = getch::Getch::new().getch().unwrap() as char;
match c {
'q' | 'Q' => break,
'a' | 'A' => {
self.add_qso();
}
......@@ -73,6 +77,11 @@ impl App {
'd' | 'D' => {
self.del_qso();
}
'c' | 'C' => {
self.edit_station_callsign();
}
'q' | 'Q' => break,
_ => {}
}
......@@ -102,6 +111,9 @@ impl App {
clearscreen::clear().unwrap();
// Header
println!("Station: {}", self.state.station.callsign);
// Table
print!("{}", table.render());
}
......@@ -160,6 +172,11 @@ impl App {
}
}
fn edit_station_callsign(&mut self) {
self.state.station.callsign =
Self::prompt("Station Callsign", self.state.station.callsign.clone()).to_uppercase();
}
fn modify_qso(&mut self, mut qso: Qso, id: usize) -> Option<Qso> {
loop {
clearscreen::clear().unwrap();
......@@ -186,13 +203,13 @@ impl App {
qso.freq = Self::prompt("Frequency (kHz)", qso.freq);
}
'm' | 'M' => {
qso.mode = Self::prompt("Mode", qso.mode);
qso.mode = Self::prompt("Mode", qso.mode).to_uppercase();
}
'p' | 'P' => {
qso.power = Self::prompt("Power", qso.power);
}
'c' | 'C' => {
qso.callsign = Self::prompt("Callsign", qso.callsign);
qso.callsign = Self::prompt("Callsign", qso.callsign).to_uppercase();
}
'q' | 'Q' => {
qso.qth = Self::prompt("QTH", qso.qth);
......
mod app;
mod qso;
mod station;
mod traits;
use crate::app::App;
......
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct Station {
#[serde(default = "default_call")]
pub callsign: String,
}
impl Default for Station {
fn default() -> Self {
Self {
callsign: "NOCALL".to_string(),
}
}
}
fn default_call() -> String {
"N0CALL".to_string()
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment