Compare commits

...

2 Commits

Author SHA1 Message Date
mars 69068d926d Brighten default black 2022-10-06 18:30:50 -06:00
mars 8df52e52a2 Add config file for colors and fonts 2022-10-06 18:21:59 -06:00
8 changed files with 207 additions and 62578 deletions

78
Cargo.lock generated
View File

@ -50,6 +50,12 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "arrayvec"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6"
[[package]]
name = "atty"
version = "0.2.14"
@ -177,6 +183,18 @@ dependencies = [
"objc",
]
[[package]]
name = "confy"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5069e3065d9ad485706017d12bb4b4318170b8087358c163c2dfce50b6b38275"
dependencies = [
"directories",
"serde",
"thiserror",
"toml",
]
[[package]]
name = "core-foundation"
version = "0.9.3"
@ -259,6 +277,16 @@ dependencies = [
"syn",
]
[[package]]
name = "directories"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "551a778172a450d7fc12e629ca3b0428d00f6afa9a43da1b630d54604e97371c"
dependencies = [
"cfg-if 0.1.10",
"dirs-sys",
]
[[package]]
name = "dirs"
version = "3.0.2"
@ -385,6 +413,17 @@ dependencies = [
"libc",
]
[[package]]
name = "hex_color"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff917051cbc87800de93ddcf39b59c9f2a0a4d809411a341c0ac422771219808"
dependencies = [
"arrayvec",
"rand",
"serde",
]
[[package]]
name = "humantime"
version = "2.1.0"
@ -833,9 +872,12 @@ version = "0.1.0"
dependencies = [
"alacritty_terminal",
"bdf",
"confy",
"env_logger",
"hex_color",
"log",
"mio-extras",
"serde",
"softbuffer",
"winit",
]
@ -846,6 +888,12 @@ version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae"
[[package]]
name = "ppv-lite86"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
[[package]]
name = "proc-macro-crate"
version = "1.2.1"
@ -875,6 +923,36 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "raw-window-handle"
version = "0.4.3"

View File

@ -9,9 +9,12 @@ description = "A bare-bones terminal emulator that is not meant to be taken too
[dependencies]
alacritty_terminal = "0.16"
confy = "0.5"
env_logger = "0.9"
hex_color = { version = "2", features = ["serde"] }
log = "0.4"
mio-extras = "2"
serde = { version = "1", features = ["derive"] }
[dependencies.bdf]
git = "https://github.com/meh/rust-bdf"

83
src/config.rs Normal file
View File

@ -0,0 +1,83 @@
use hex_color::HexColor;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
#[derive(Debug, Deserialize, Serialize)]
pub struct CursorConfig {}
#[derive(Debug, Deserialize, Serialize)]
pub struct ColorConfig {
pub background: HexColor,
pub foreground: HexColor,
pub black: HexColor,
pub red: HexColor,
pub green: HexColor,
pub yellow: HexColor,
pub blue: HexColor,
pub magenta: HexColor,
pub cyan: HexColor,
pub white: HexColor,
pub bright_black: HexColor,
pub bright_red: HexColor,
pub bright_green: HexColor,
pub bright_yellow: HexColor,
pub bright_blue: HexColor,
pub bright_magenta: HexColor,
pub bright_cyan: HexColor,
pub bright_white: HexColor,
}
#[derive(Debug, Default, Deserialize, Serialize)]
pub struct FontConfig {
pub normal: PathBuf,
pub bold: PathBuf,
}
#[derive(Debug, Default, Deserialize, Serialize)]
pub struct Config {
pub cursor: CursorConfig,
pub colors: ColorConfig,
pub fonts: FontConfig,
}
impl Default for CursorConfig {
fn default() -> Self {
Self {}
}
}
impl Default for ColorConfig {
fn default() -> Self {
let rgb = HexColor::rgb;
let black = rgb(96, 96, 96);
let red = rgb(255, 0, 0);
let green = rgb(0, 255, 0);
let yellow = rgb(255, 255, 0);
let blue = rgb(0, 0, 255);
let magenta = rgb(255, 0, 255);
let cyan = rgb(0, 255, 255);
let white = rgb(224, 224, 224);
Self {
background: rgb(0, 0, 0),
foreground: rgb(255, 255, 255),
black,
red,
green,
yellow,
blue,
magenta,
cyan,
white,
bright_black: black,
bright_red: red,
bright_green: green,
bright_yellow: yellow,
bright_blue: blue,
bright_magenta: magenta,
bright_cyan: cyan,
bright_white: white,
}
}
}

View File

@ -6,8 +6,7 @@ use softbuffer::GraphicsContext;
use std::collections::HashMap;
use winit::window::Window;
static NORMAL_FONT_DATA: &[u8] = include_bytes!("ter-u16n.bdf");
static BOLD_FONT_DATA: &[u8] = include_bytes!("ter-u16b.bdf");
use crate::config::{ColorConfig, Config, FontConfig};
use super::TermListener;
@ -133,9 +132,9 @@ pub struct GlyphCache {
}
impl GlyphCache {
pub fn new(colors: Colors) -> Self {
pub fn new(colors: Colors, font_config: &FontConfig) -> Self {
Self {
renderer: BitmapGlyphRenderer::new(),
renderer: BitmapGlyphRenderer::new(font_config),
colors,
glyphs: Default::default(),
}
@ -180,9 +179,9 @@ pub struct BitmapGlyphRenderer {
}
impl BitmapGlyphRenderer {
pub fn new() -> Self {
let normal_font = bdf::read(NORMAL_FONT_DATA).unwrap();
let bold_font = bdf::read(BOLD_FONT_DATA).unwrap();
pub fn new(font_config: &FontConfig) -> Self {
let normal_font = bdf::open(&font_config.normal).unwrap();
let bold_font = bdf::open(&font_config.bold).unwrap();
if normal_font.bounds() != bold_font.bounds() {
panic!("Normal and bold font bounds do not match!");
@ -250,13 +249,13 @@ pub struct Graphics {
}
impl Graphics {
pub fn new() -> Self {
pub fn new(config: &Config) -> Self {
let canvas = Canvas::new(2000, 2000);
let mut colors = Colors::default();
Self::load_colors(&mut colors);
Self::load_colors(&config.colors, &mut colors);
let glyph_cache = GlyphCache::new(colors.clone());
let glyph_cache = GlyphCache::new(colors.clone(), &config.fonts);
let cell_cache = Default::default();
Self {
@ -269,49 +268,37 @@ impl Graphics {
}
}
pub fn load_colors(color: &mut Colors) {
pub fn load_colors(config: &ColorConfig, colors: &mut Colors) {
use NamedColor::*;
let hex = |hex: u32| -> Rgb {
Rgb {
r: (hex >> 16) as u8,
g: (hex >> 8) as u8,
b: hex as u8,
}
let mut set = |color: NamedColor, value: hex_color::HexColor| {
let rgb = Rgb {
r: value.r,
g: value.g,
b: value.b,
};
colors[color] = Some(rgb);
};
// Rose Pine theme
let maps = [
(Foreground, hex(0xe0def4)),
(Background, hex(0x191724)),
(Black, hex(0x6e6a86)),
(Red, hex(0xeb6f92)),
(Green, hex(0x7fb59f)),
(Yellow, hex(0xf6c177)),
(Blue, hex(0x31748f)),
(Magenta, hex(0xc4a7e7)),
(Cyan, hex(0x9ccfd8)),
(White, hex(0xe0def4)),
];
for map in maps.iter() {
color[map.0] = Some(map.1);
}
let dupes = [
(BrightBlack, Black),
(BrightRed, Red),
(BrightGreen, Green),
(BrightYellow, Yellow),
(BrightBlue, Blue),
(BrightMagenta, Magenta),
(BrightCyan, Cyan),
(BrightWhite, White),
];
for (dst, src) in dupes.iter() {
color[*dst] = color[*src];
}
set(Background, config.background);
set(Foreground, config.foreground);
set(Black, config.black);
set(Red, config.red);
set(Green, config.green);
set(Yellow, config.yellow);
set(Blue, config.blue);
set(Magenta, config.magenta);
set(Cyan, config.cyan);
set(White, config.white);
set(BrightBlack, config.bright_black);
set(BrightRed, config.bright_red);
set(BrightGreen, config.bright_green);
set(BrightYellow, config.bright_yellow);
set(BrightBlue, config.bright_blue);
set(BrightMagenta, config.bright_magenta);
set(BrightCyan, config.bright_cyan);
set(BrightWhite, config.bright_white);
}
pub fn color_to_u32(&self, color: &Color) -> u32 {

View File

@ -20,8 +20,10 @@ use winit::event::{Event, WindowEvent};
use winit::event_loop::{ControlFlow, EventLoop};
use winit::window::{Window, WindowBuilder, WindowId};
pub mod config;
pub mod graphics;
use config::Config;
use graphics::Graphics;
pub struct TermListener {
@ -51,8 +53,8 @@ pub struct App {
}
impl App {
pub fn new(window: Window) -> Self {
let graphics = Graphics::new();
pub fn new(config: Config, window: Window) -> Self {
let graphics = Graphics::new(&config);
let term_size = alacritty_terminal::term::SizeInfo::new(
graphics.canvas.width as f32,
@ -205,11 +207,13 @@ impl App {
}
fn main() {
let config: Config = confy::load("piss", Some("config")).unwrap();
env_logger::init();
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
let mut app = App::new(window);
let mut app = App::new(config, window);
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,94 +0,0 @@
Copyright (C) 2020 Dimitar Toshkov Zhekov,
with Reserved Font Name "Terminus Font".
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.