Skip to content

Commit

Permalink
New branding on install and Repl (#1397)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmastrac authored Nov 22, 2024
1 parent 5f22cb7 commit 6a5f1c4
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ portable_tests = []
docker_test_wrapper = []
gel = []


[workspace.dependencies]
clap = "4.4.6"
termimad = "0.30.0"
Expand Down Expand Up @@ -137,6 +136,7 @@ bitvec = "1.0.1"
nom = "7.1.3"
bitflags = "2.6"
renamore = "0.3.2"
anes = "0.2.0"

[dependencies.bzip2]
version = "*"
Expand Down
7 changes: 4 additions & 3 deletions src/cli/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
use std::env;
use std::fs;
use std::fs::OpenOptions;
use std::io::Seek;
use std::io::SeekFrom;
use std::io::{stdout, BufWriter, Write};
use std::io::{stdout, BufWriter, Seek, SeekFrom, Write};
use std::path::{Path, PathBuf};
use std::process::exit;
use std::str::FromStr;
Expand All @@ -21,6 +19,7 @@ use prettytable::{Cell, Row, Table};
use crate::branding::BRANDING_CLI_CMD_ALT_FILE;
use crate::branding::BRANDING_CLI_CMD_FILE;
use crate::branding::{BRANDING, BRANDING_CLI, BRANDING_CLI_CMD};
use crate::cli::logo::print_logo;
use crate::cli::{migrate, upgrade};
use crate::commands::ExitCode;
use crate::options::Options;
Expand Down Expand Up @@ -103,6 +102,8 @@ pub struct Settings {
fn print_long_description(settings: &Settings) {
println!();

print_logo(true, false);

print_markdown!(
"\
# Welcome to ${branding}!\n\
Expand Down
122 changes: 122 additions & 0 deletions src/cli/logo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
use std::io::IsTerminal;
use std::io::{stdout, Write};

use crate::print;
use anes::*;

macro_rules! write_ansi {
($($args:tt)*) => {
_ = write!(stdout(), "{}",$($args)*);
}
}

pub fn print_logo(allow_animation: bool, small: bool) {
if !cfg!(feature = "gel") {
return;
}

if !print::use_utf8() {
return;
}

let logo = if small {
include_str!("logo_blocks.txt")
} else {
include_str!("logo.txt")
};

let lines = logo.lines().collect::<Vec<_>>();
let line_count = lines.len() as u16;
let line_width = lines
.iter()
.map(|line: &&str| line.chars().count())
.max()
.unwrap();

let normal = |c| {
write_ansi!(ResetAttributes);
write_ansi!(SetAttribute(Attribute::Bold));
if c == '$' || c == '█' || c == '▄' || c == '▀' {
write_ansi!(SetForegroundColor(Color::Magenta));
} else {
write_ansi!(SetForegroundColor(Color::Yellow));
}
write_ansi!(SetAttribute(Attribute::Bold));
};

let highlight = || {
write_ansi!(SetForegroundColor(Color::White));
};

if !cfg!(windows) && allow_animation && stdout().is_terminal() && print::use_color() {
const TRAILING_HIGHLIGHT_COLS: usize = 5;
const FRAME_DELAY: u64 = 20;

for _ in 0..line_count {
eprintln!();
}

write_ansi!(MoveCursorUp(line_count + 1));

for line in &lines {
for char in line.chars() {
normal(char);
write_ansi!(char);
}
write_ansi!("\n");
std::thread::sleep(std::time::Duration::from_millis(FRAME_DELAY));
}
write_ansi!("\n");

write_ansi!(SaveCursorPosition);
write_ansi!(HideCursor);

for col in 0..line_width + TRAILING_HIGHLIGHT_COLS {
_ = stdout().flush();
std::thread::sleep(std::time::Duration::from_millis(FRAME_DELAY));

write_ansi!(MoveCursorUp(line_count + 1));
for line in &lines {
// Unhighlight the previous trailing column
if col >= TRAILING_HIGHLIGHT_COLS {
write_ansi!(MoveCursorLeft(TRAILING_HIGHLIGHT_COLS as u16));
let char = line
.chars()
.nth(col - TRAILING_HIGHLIGHT_COLS)
.unwrap_or(' ');
normal(char);
write_ansi!(char);
if TRAILING_HIGHLIGHT_COLS > 1 {
write_ansi!(MoveCursorRight((TRAILING_HIGHLIGHT_COLS - 1) as u16));
}
}
if let Some(c) = line.chars().nth(col) {
highlight();
write_ansi!(c);
} else {
normal(' ');
write_ansi!(' ');
}
write_ansi!(MoveCursorLeft(1 as u16));
write_ansi!(MoveCursorDown(1 as u16));
}
write_ansi!(MoveCursorDown(1 as u16));
write_ansi!(MoveCursorRight(1 as u16));
}
write_ansi!(ShowCursor);
write_ansi!(RestoreCursorPosition);
write_ansi!(ResetAttributes);
} else {
if print::use_color() {
for line in &lines {
for char in line.chars() {
normal(char);
write_ansi!(char);
}
write_ansi!("\n");
}
} else {
println!("{}", logo);
}
}
}
16 changes: 16 additions & 0 deletions src/cli/logo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/$$$$
/$$$$$$
| $$$$$$
/$$$$$$$$ /$$$$$$$ | $$$$$$
/$$$$$$$$$$$$ /$$$$$$$$$$$ | $$$$$$
/$$$$$$$$$$$$$$ /$$$$$$$$$$$$$ | $$$$$$
| $$$$$$$$$$$$$$ | $$$$$$$$$$$$$ | $$$$$$
\ $$$$$$$$$$$$ \ $$$$$$$/ | $$$$$$
\_ $$$$$$$$_/ \_ $$$$$$$ \ $$$$/
\_______/ \______/ \___/

/$ $
| $$$$$$$$$$$$
| $$$$$$$$$$$$
\__ $$$$$$_/
\_____/
7 changes: 7 additions & 0 deletions src/cli/logo_blocks.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
▄██▄
▄▄▄▄▄ ▄▄▄ ████
▄███████▄ ▄███████▄ ████
▀███████▀ ▀███▀▀▀▀▀ ████
▀▀▀▀▀ ▀▀▀ ▀▀
▀▄▄▄▄▄▀
▀▀▀
1 change: 1 addition & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod directory_check;
pub mod env;
pub mod install;
pub mod logo;
pub mod main;
pub mod migrate;
pub mod options;
Expand Down
2 changes: 2 additions & 0 deletions src/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use edgeql_parser::preparser::{self, full_statement};

use crate::analyze;
use crate::classify;
use crate::cli::logo::print_logo;
use crate::commands::{backslash, ExitCode};
use crate::config::Config;
use crate::credentials;
Expand Down Expand Up @@ -143,6 +144,7 @@ pub fn main(options: Options, cfg: Config) -> Result<(), anyhow::Error> {
edgeql_state: State::empty(),
current_branch: None,
};
print_logo(false, true);
let runtime = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()?;
Expand Down
21 changes: 21 additions & 0 deletions src/print/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::convert::Infallible;
use std::error::Error;
use std::fmt;
use std::io;
use std::sync::OnceLock;

use colorful::{Color, Colorful};
use const_format::concatcp;
Expand Down Expand Up @@ -379,6 +380,26 @@ pub fn json_item_to_string<I: FormatExt>(item: &I, config: &Config) -> Result<St
Ok(out)
}

/// Does this terminal support UTF-8?
pub fn use_utf8() -> bool {
static UTF8_ENV: OnceLock<bool> = OnceLock::new();

let utf8_env = UTF8_ENV.get_or_init(|| {
let env_vars = ["LANG", "LC_CTYPE", "LC_ALL"];
env_vars.iter().any(|var| {
std::env::var_os(var)
.map(|v| {
let v = v.to_str().unwrap_or_default();
v.contains("UTF8") || v.contains("UTF-8")
})
.unwrap_or(false)
})
});

cfg!(windows) || *utf8_env
}

/// Does this terminal support ANSI colors?
pub fn use_color() -> bool {
concolor::get(concolor::Stream::Stdout).ansi_color()
}
Expand Down

0 comments on commit 6a5f1c4

Please sign in to comment.