Skip to content

Commit

Permalink
Set max prompt limit and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
shettysach committed Feb 25, 2024
1 parent c5c7166 commit c0098f4
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 114 deletions.
20 changes: 3 additions & 17 deletions src/base/banner.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
use leptos::{component, view, IntoView};

pub const HELP: &str = r#"<span class="grn semibold"> ________________ __ _____________ __ ________
/_ __/ ____/ __ \/ |/ / ____/ __ \/ / / _/ __ \
/ / / __/ / /_/ / /|_/ / /_ / / / / / / // / / /
/ / / /___/ _, _/ / / / __/ / /_/ / /____/ // /_/ /
/_/ /_____/_/ |_/_/ /_/_/ \____/_____/___/\____/
</span>
Hello, welcome to <u class="blu semibold">Termfolio</u>. Type one of these commands -
<span class="rd semibold">about</span> - View about me
<span class="rd semibold">github</span> - View about Github profile
<span class="rd semibold">repos</span> - View about my pinned repos / projects
<span class="rd semibold">links</span> - View contact info and links
<span class="rd semibold">help</span> - View this help section
<span class="rd semibold">theme</span> - Cycle through themes
<span class="rd semibold">credits</span> - View credits and repo"#;

#[component]
pub fn Banner() -> impl IntoView {
let banner = termfolio::banner();

view! {
<p class="inline">"user@termfolio:~$ "</p>
<p style="display:inline;padding:2px;">"help"</p>
<pre>
<div class="output" inner_html={HELP}></div>
<div class="output" inner_html={banner}></div>
</pre>
}
}
2 changes: 1 addition & 1 deletion src/base/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub fn Prompt(
<p class="inline">"user@termfolio:~$ "</p>
<input
id="prompt-form" autocomplete="off"
class="inp" type="text" maxlength=42 spellcheck="false"
class="inp" type="text" maxlength=38 spellcheck="false"
value=out node_ref=input_element/>
</form>
<pre>
Expand Down
9 changes: 7 additions & 2 deletions src/base/prompt/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@ pub async fn general_commands<F>(
}
});

// Clears if max limit is reached
submitter.update(|prompts| {
if *prompts < u8::MAX {
*prompts += 1;
if *prompts == u8::MAX {
*prompts = 0;
}
});

submitter.update(|prompts| {
*prompts += 1;
});
}
86 changes: 5 additions & 81 deletions src/fetch.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
use serde::{Deserialize, Serialize};
use std::sync::OnceLock;
use tokio::sync::OnceCell;
use tokio::try_join;

// Formnatting functions and error messages
mod formats;
use crate::texts::{FETCH_GITHUB_ERROR, READ_JSON_ERROR};
use formats::*;

// Config JSON
// Structs for JSON Parsing
mod structs;
use structs::*;

// Config JSON
const JSON: &str = include_str!("../configs/config.json");

// Once statics
Expand All @@ -18,85 +21,6 @@ static GITHUB: OnceCell<String> = OnceCell::const_new();
static REPOS: OnceCell<String> = OnceCell::const_new();
static CONTACTS: OnceLock<String> = OnceLock::new();

// Structs

#[derive(Deserialize, Serialize, Clone)]
pub struct Config {
pub github: String,
pub about: About,
pub links: Links,
}

#[derive(Deserialize, Serialize, Clone)]
pub struct About {
pub name: String,
pub intro: String,
pub interests: Vec<String>,
pub langs: Vec<String>,
pub experience: Vec<Experience>,
pub education: Vec<Education>,
}

#[derive(Deserialize, Serialize, Clone)]
pub struct Experience {
pub title: String,
pub description: Vec<String>,
}

#[derive(Deserialize, Serialize, Clone)]
pub struct Education {
pub institute: String,
pub course: String,
pub duration: String,
}

#[derive(Deserialize, Serialize, Clone)]
pub struct Links {
pub github: String,
pub email: Option<String>,
pub linkedin: Option<String>,
pub twitter: Option<String>,
}

#[derive(Deserialize, Serialize, Clone)]
pub struct UserInfo {
pub name: Option<String>,
pub bio: Option<String>,
pub public_repos: u16,
pub company: Option<String>,
pub location: Option<String>,
pub followers: u16,
pub following: u16,
pub created_at: String,
}

#[derive(Deserialize, Serialize, Clone)]
pub struct UserStats {
pub stars: u16,
pub forks: u16,
}

#[derive(Deserialize, Serialize)]
pub struct ApiResponse {
pub response: Vec<Repository>,
}

#[derive(Deserialize, Serialize, Clone)]
pub struct Repository {
pub name: String,
pub repo: String,
pub description: String,
pub language: Language,
pub stars: u16,
pub forks: u16,
}

#[derive(Deserialize, Serialize, Clone)]
pub struct Language {
pub name: String,
pub color: String,
}

// Once Functions

fn read_config() -> Option<Config> {
Expand Down
4 changes: 2 additions & 2 deletions src/fetch/formats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pub fn format_repos(username: String, repos: Vec<Repository>) -> String {
format!(
r#"<div class="row">
<div class="rcols">{}</div>
<div class="rcols" style="max-width: 50%;">{}</div>
<div class="rcols" style="width: 45%;">{}</div>
</div>"#,
lang_icon(&repo.language.name),
text
Expand All @@ -187,7 +187,7 @@ pub fn format_repos(username: String, repos: Vec<Repository>) -> String {
let all = format!(
r#"<div class="row">
<div class="rcols">{}</div>
<div class="rcols" style="max-width: 50%;">{}</div>
<div class="rcols" style="width: 45%;">{}</div>
</div>"#,
PLACEHOLDER, all_link
);
Expand Down
78 changes: 78 additions & 0 deletions src/fetch/structs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize, Clone)]
pub struct Config {
pub github: String,
pub about: About,
pub links: Links,
}

#[derive(Deserialize, Serialize, Clone)]
pub struct About {
pub name: String,
pub intro: String,
pub interests: Vec<String>,
pub langs: Vec<String>,
pub experience: Vec<Experience>,
pub education: Vec<Education>,
}

#[derive(Deserialize, Serialize, Clone)]
pub struct Experience {
pub title: String,
pub description: Vec<String>,
}

#[derive(Deserialize, Serialize, Clone)]
pub struct Education {
pub institute: String,
pub course: String,
pub duration: String,
}

#[derive(Deserialize, Serialize, Clone)]
pub struct Links {
pub github: String,
pub email: Option<String>,
pub linkedin: Option<String>,
pub twitter: Option<String>,
}

#[derive(Deserialize, Serialize, Clone)]
pub struct UserInfo {
pub name: Option<String>,
pub bio: Option<String>,
pub public_repos: u16,
pub company: Option<String>,
pub location: Option<String>,
pub followers: u16,
pub following: u16,
pub created_at: String,
}

#[derive(Deserialize, Serialize, Clone)]
pub struct UserStats {
pub stars: u16,
pub forks: u16,
}

#[derive(Deserialize, Serialize)]
pub struct ApiResponse {
pub response: Vec<Repository>,
}

#[derive(Deserialize, Serialize, Clone)]
pub struct Repository {
pub name: String,
pub repo: String,
pub description: String,
pub language: Language,
pub stars: u16,
pub forks: u16,
}

#[derive(Deserialize, Serialize, Clone)]
pub struct Language {
pub name: String,
pub color: String,
}
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ pub fn autocomplete(inp: &str) -> &str {
let inp = inp.trim();

let comms = [
"help", "history", "about", "github", "repos", "links", "theme", "credits", "neofetch",
"help", "history", "about", "github", "repos", "links", "theme", "wal", "credits",
"neofetch",
];

if !inp.is_empty() {
Expand All @@ -116,3 +117,7 @@ pub fn autocomplete(inp: &str) -> &str {

inp
}

pub fn banner() -> String {
String::from(texts::HELP)
}
8 changes: 5 additions & 3 deletions src/texts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pub const HELP: &str = r#"<span class="grn semibold"> ________________ __ ___
/ / / /___/ _, _/ / / / __/ / /_/ / /____/ // /_/ /
/_/ /_____/_/ |_/_/ /_/_/ \____/_____/___/\____/
</span>
Hello, welcome to <u class="blu semibold">Termfolio</u>. Type one of these commands -
<span class="rd semibold">about</span> - View about me
Expand All @@ -22,7 +21,8 @@ pub const CREDITS: &str = r#"<span class="grn"> _____ ______________ _________
| | | |___| |\ \| | | || | \ \_/ / |_____| |_\ \_/ /
\_/ \____/\_| \_\_| |_/\_| \___/\_____/\___/ \___/
</span>
Terminal style portfolio website, made in Leptos, Rust.
Terminal style portfolio website,
made using <span class="grn">Leptos - Rust and WASM (WebAssembly)</span>.
Made by <span class="rd semibold">Sachith C Shetty</span>
<a href="https://github.com/shettysach" target="_blank" class="blu semibold">Github</a>: github.com/shettysach
Expand All @@ -44,7 +44,9 @@ Made by <span class="rd semibold">Sachith C Shetty</span>
* <a
href="https://github.com/idealclover/GitHub-Star-Counter"
target="_blank"
class="blu semibold">Total stars and forks</a> - idealclover/GitHub-Star-Counter"#;
class="blu semibold">Total stars and forks</a> - idealclover/GitHub-Star-Counter
"#;

pub const READ_JSON_ERROR: &str = r#"<span class="rd semibold">Error reading config.json</span>"#;
pub const FETCH_GITHUB_ERROR: &str =
Expand Down
10 changes: 3 additions & 7 deletions styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@

* {
font-family: "IBM Plex Mono";
font-size: 20px;
font-size: 19px;
background: var(--black);
color: var(--white);
text-underline-offset: 8px;
text-decoration-thickness: 2px;
/* text-shadow: 0px 5px 10px currentColor; */
}

Expand Down Expand Up @@ -114,9 +116,3 @@ form {
font-size: 35px;
}

/* Links */

a {
text-decoration-thickness: 2px;
text-underline-offset: 8px;
}

0 comments on commit c0098f4

Please sign in to comment.