| 1 | //! beer, a fast, software-rendered, Wayland-native terminal emulator. |
| 2 | |
| 3 | mod config; |
| 4 | mod font; |
| 5 | mod grid; |
| 6 | mod input; |
| 7 | mod pty; |
| 8 | mod render; |
| 9 | mod theme; |
| 10 | mod vt; |
| 11 | mod wayland; |
| 12 | |
| 13 | use std::path::PathBuf; |
| 14 | use std::process::ExitCode; |
| 15 | |
| 16 | use pound::Parse; |
| 17 | |
| 18 | use crate::config::Config; |
| 19 | |
| 20 | /// A fast, software-rendered, Wayland-native terminal emulator. |
| 21 | #[derive(Parse)] |
| 22 | #[pound(name = "beer", version = "0.0.0")] |
| 23 | struct Cli { |
| 24 | /// Run as a daemon hosting multiple windows. |
| 25 | #[pound(long)] |
| 26 | server: bool, |
| 27 | /// Path to a config file (default: $XDG_CONFIG_HOME/beer/beer.toml). |
| 28 | #[pound(long)] |
| 29 | config: Option<PathBuf>, |
| 30 | } |
| 31 | |
| 32 | fn main() -> ExitCode { |
| 33 | init_logging(); |
| 34 | match run(Cli::parse()) { |
| 35 | Ok(code) => code, |
| 36 | Err(err) => { |
| 37 | tracing::error!("{err:#}"); |
| 38 | eprintln!("beer: {err:#}"); |
| 39 | ExitCode::FAILURE |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | fn init_logging() { |
| 45 | use tracing_subscriber::{EnvFilter, fmt}; |
| 46 | |
| 47 | let filter = EnvFilter::try_from_env("BEER_LOG") |
| 48 | .or_else(|_| EnvFilter::try_from_default_env()) |
| 49 | .unwrap_or_else(|_| EnvFilter::new("warn")); |
| 50 | |
| 51 | fmt() |
| 52 | .with_env_filter(filter) |
| 53 | .with_writer(std::io::stderr) |
| 54 | .init(); |
| 55 | } |
| 56 | |
| 57 | fn run(cli: Cli) -> anyhow::Result<ExitCode> { |
| 58 | if cli.server { |
| 59 | anyhow::bail!("server mode is not implemented yet"); |
| 60 | } |
| 61 | |
| 62 | let config = Config::load(cli.config.as_deref()); |
| 63 | tracing::info!("starting beer"); |
| 64 | wayland::run(config) |
| 65 | } |