Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
limalogger
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stephen D
limalogger
Commits
fc552175
Commit
fc552175
authored
3 years ago
by
Stephen D
Browse files
Options
Downloads
Patches
Plain Diff
Add ability to edit qsos
parent
c2c61b09
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app.rs
+44
-25
44 additions, 25 deletions
src/app.rs
src/qso.rs
+1
-0
1 addition, 0 deletions
src/qso.rs
with
45 additions
and
25 deletions
src/app.rs
+
44
−
25
View file @
fc552175
...
...
@@ -18,8 +18,9 @@ impl App {
pub
fn
run
(
&
mut
self
)
{
loop
{
self
.render_
main
();
self
.render_
table
();
println!
(
"
\t
[A] Add QSO
\t
[E] Edit QSO
\t
[D] Del QSO
\t
[Q] Quit"
);
// Wish this had unicode support ):
let
c
=
getch
::
Getch
::
new
()
.getch
()
.unwrap
()
as
char
;
match
c
{
...
...
@@ -27,6 +28,9 @@ impl App {
'a'
|
'A'
=>
{
self
.add_qso
();
}
'e'
|
'E'
=>
{
self
.edit_qso
();
}
'd'
|
'D'
=>
{
self
.del_qso
();
}
...
...
@@ -37,12 +41,6 @@ impl App {
}
}
fn
render_main
(
&
self
)
{
self
.render_table
();
println!
(
"
\t
[A] Add QSO
\t
[D] Del QSO
\t
[Q] Quit"
);
}
fn
render_table
(
&
self
)
{
let
mut
rows
=
vec!
[
Qso
::
table_header
()];
rows
.extend
(
self
.qsos
.iter
()
.enumerate
()
.map
(|(
i
,
qso
)|
qso
.to_row
(
i
)));
...
...
@@ -66,7 +64,7 @@ impl App {
(
qso
.freq
.clone
(),
qso
.mode
.clone
(),
qso
.power
)
});
let
mut
qso
=
Qso
{
let
qso
=
Qso
{
time
:
Utc
::
now
(),
freq
,
mode
,
...
...
@@ -78,6 +76,41 @@ impl App {
comments
:
String
::
new
(),
};
if
let
Some
(
qso
)
=
self
.modify_qso
(
qso
,
self
.qsos
.len
())
{
self
.qsos
.push
(
qso
);
}
}
fn
edit_qso
(
&
mut
self
)
{
print!
(
"Id [Blank to cancel]? "
);
Self
::
flush
();
let
mut
buffer
=
String
::
new
();
stdin
()
.read_line
(
&
mut
buffer
)
.unwrap
();
let
buffer
=
buffer
.trim
();
if
let
Ok
(
id
)
=
buffer
.parse
::
<
usize
>
()
{
if
id
<
self
.qsos
.len
()
{
let
qso
=
self
.qsos
[
id
]
.clone
();
if
let
Some
(
qso
)
=
self
.modify_qso
(
qso
,
id
)
{
self
.qsos
[
id
]
=
qso
;
}
}
}
}
fn
del_qso
(
&
mut
self
)
{
print!
(
"Id [Blank to cancel]? "
);
Self
::
flush
();
let
mut
buffer
=
String
::
new
();
stdin
()
.read_line
(
&
mut
buffer
)
.unwrap
();
let
buffer
=
buffer
.trim
();
if
let
Ok
(
id
)
=
buffer
.parse
()
{
if
id
<
self
.qsos
.len
()
{
self
.qsos
.remove
(
id
);
}
}
}
fn
modify_qso
(
&
mut
self
,
mut
qso
:
Qso
,
id
:
usize
)
->
Option
<
Qso
>
{
loop
{
clearscreen
::
clear
()
.unwrap
();
...
...
@@ -87,7 +120,7 @@ impl App {
Qso
::
table_header_with_suffixes
(
&
[
""
,
"[T]"
,
"[F]"
,
"[M]"
,
"[P]"
,
"[C]"
,
"[Q]"
,
"[E]"
,
"[R]"
,
"[O]"
,
]),
qso
.to_row
(
self
.qsos
.len
()
),
qso
.to_row
(
id
),
])
.build
();
table
.max_column_width
=
MAX_COLUMN_WIDTH
;
...
...
@@ -123,30 +156,16 @@ impl App {
qso
.comments
=
Self
::
prompt
(
"Comments"
,
qso
.comments
);
}
's'
|
'S'
=>
{
self
.qsos
.push
(
qso
);
break
;
break
Some
(
qso
);
}
'x'
|
'X'
=>
{
break
;
break
None
;
}
_
=>
{}
}
}
}
fn
del_qso
(
&
mut
self
)
{
print!
(
"Id [Blank to cancel]? "
);
Self
::
flush
();
let
mut
buffer
=
String
::
new
();
stdin
()
.read_line
(
&
mut
buffer
)
.unwrap
();
let
buffer
=
buffer
.trim
();
if
let
Ok
(
id
)
=
buffer
.parse
()
{
if
id
<
self
.qsos
.len
()
{
self
.qsos
.remove
(
id
);
}
}
}
fn
prompt
<
T
:
TuiValue
>
(
label
:
&
str
,
default
:
T
)
->
T
{
println!
();
...
...
This diff is collapsed.
Click to expand it.
src/qso.rs
+
1
−
0
View file @
fc552175
...
...
@@ -2,6 +2,7 @@ use chrono::{DateTime, Utc};
use
term_table
::
row
::
Row
;
use
term_table
::
table_cell
::
TableCell
;
#[derive(Clone)]
pub
struct
Qso
{
pub
time
:
DateTime
<
Utc
>
,
pub
freq
:
String
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment