-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: minimal type fast functionality
- Loading branch information
Showing
7 changed files
with
207 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,7 @@ | |
|
||
|
||
run: | ||
cargo run | ||
cargo run | ||
|
||
hurl: | ||
hurl basic.hurl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use rand::Rng; | ||
|
||
|
||
|
||
|
||
|
||
pub fn random_letters(max: u32) -> String { | ||
let mut rng = rand::thread_rng(); | ||
let mut s: String = "".into(); | ||
for _i in 0..max { | ||
let letter: char = rng.gen_range(b'A'..=b'Z') as char; | ||
let manipulated = big_small_space(letter); | ||
s.push(manipulated) | ||
} | ||
s.trim().to_string() | ||
} | ||
|
||
fn big_small_space(letter: char) -> char { | ||
let mut rng = rand::thread_rng(); | ||
let lr = rng.gen_range(0..3); | ||
match lr { | ||
0 => letter, | ||
1 => { | ||
let chars: Vec<char> = letter.to_lowercase().to_string().chars().collect(); | ||
chars[0] | ||
} | ||
2 => ' ', | ||
_ => letter, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use egui::Ui; | ||
|
||
#[derive(serde::Deserialize, serde::Serialize)] | ||
#[serde(default)] // if we add new fields, give them default values when deserializing old state | ||
pub struct TFSetting { | ||
pub command: String, | ||
pub settings_open: bool, | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
impl Default for TFSetting { | ||
fn default() -> Self { | ||
Self { | ||
command: Default::default(), | ||
settings_open: false, | ||
} | ||
} | ||
} | ||
|
||
impl TFSetting { | ||
pub fn process_command(&mut self, ui: &mut Ui, ctx: &egui::Context) { | ||
let command = self.command.clone(); | ||
if self.command.contains(";") { | ||
self.command.clear(); | ||
} | ||
|
||
if command.eq("") { | ||
ui.label(&self.command); | ||
} | ||
|
||
if command.eq("open settings;") { | ||
self.settings_open = true | ||
} | ||
|
||
if command.eq("close settings;") { | ||
self.settings_open = false | ||
} | ||
|
||
if self.settings_open { | ||
egui::Window::new("Draft setting").show(ctx, |ui| { | ||
ui.label("Hey"); | ||
if ui.button("close").clicked() { | ||
self.settings_open = false | ||
} | ||
}); | ||
} | ||
} | ||
pub fn command_helpers(&mut self, ui: &mut Ui,){ | ||
ui.spacing_mut().item_spacing.x = 0.5; | ||
if ui.button("open settings").clicked() { | ||
self.command = "open settings;".into(); | ||
} | ||
if ui.button("close settings").clicked() { | ||
self.command = "close settings;".into(); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use egui::{Ui, RichText}; | ||
|
||
#[derive(serde::Deserialize, serde::Serialize)] | ||
#[serde(default)] // if we add new fields, give them default values when deserializing old state | ||
pub struct TypeState { | ||
input: String, | ||
challenge: String, | ||
} | ||
|
||
impl Default for TypeState { | ||
fn default() -> Self { | ||
Self { | ||
input: Default::default(), | ||
challenge: Default::default(), | ||
} | ||
} | ||
} | ||
|
||
pub trait Challenge { | ||
fn into_challenge(&self) -> String; | ||
} | ||
|
||
|
||
|
||
impl TypeState { | ||
pub fn render(&mut self, ui: &mut Ui, provider: &(impl Challenge + ?Sized)) { | ||
//win condition | ||
if self.input.eq(&self.challenge) { | ||
self.challenge.clear(); | ||
self.input.clear(); | ||
self.challenge = provider.into_challenge(); | ||
} | ||
|
||
let challenge_text = RichText::new(self.challenge.to_string()).size(90.0); | ||
ui.heading(challenge_text); | ||
|
||
let input_text = RichText::new(self.input.to_string()).size(90.0); | ||
ui.heading(input_text); | ||
|
||
ui.text_edit_multiline(&mut self.input); | ||
|
||
ui.label(""); | ||
ui.label(""); | ||
ui.label(""); | ||
ui.label(""); | ||
ui.label(""); | ||
ui.label(""); | ||
ui.label(""); | ||
ui.label(""); | ||
ui.label(""); | ||
ui.label(""); | ||
ui.label(""); | ||
ui.label(""); | ||
ui.label(""); | ||
ui.label(""); | ||
|
||
|
||
|
||
} | ||
} | ||
|
||
|