Initial commit
This commit is contained in:
commit
18a5892371
6 changed files with 3600 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
3432
Cargo.lock
generated
Normal file
3432
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
13
Cargo.toml
Normal file
13
Cargo.toml
Normal file
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "cri"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
color-eyre = "0.6.2"
|
||||
futures = "0.3.29"
|
||||
iced = { version = "0.10.0", features = ["tokio"] }
|
||||
irc = "0.15.0"
|
||||
tokio = { version = "1.33.0", features = ["full"] }
|
1
rust-toolchain
Normal file
1
rust-toolchain
Normal file
|
@ -0,0 +1 @@
|
|||
stable
|
49
shell.nix
Normal file
49
shell.nix
Normal file
|
@ -0,0 +1,49 @@
|
|||
{ pkgs ? import <nixpkgs> {} }:
|
||||
pkgs.mkShell rec {
|
||||
buildInputs = with pkgs; [
|
||||
cargo
|
||||
clang
|
||||
llvmPackages.bintools
|
||||
watchexec
|
||||
pkg-config
|
||||
openssl
|
||||
|
||||
libxkbcommon
|
||||
libGL
|
||||
|
||||
# WINIT_UNIX_BACKEND=wayland
|
||||
wayland
|
||||
|
||||
# WINIT_UNIX_BACKEND=x11
|
||||
xorg.libXcursor
|
||||
xorg.libXrandr
|
||||
xorg.libXi
|
||||
xorg.libX11
|
||||
];
|
||||
RUSTC_VERSION = pkgs.lib.readFile ./rust-toolchain;
|
||||
# https://github.com/rust-lang/rust-bindgen#environment-variables
|
||||
LIBCLANG_PATH = pkgs.lib.makeLibraryPath [ pkgs.llvmPackages_latest.libclang.lib ];
|
||||
shellHook = ''
|
||||
export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin
|
||||
export PATH=$PATH:''${RUSTUP_HOME:-~/.rustup}/toolchains/$RUSTC_VERSION-x86_64-unknown-linux-gnu/bin/
|
||||
'';
|
||||
# Add libvmi precompiled library to rustc search path
|
||||
RUSTFLAGS = (builtins.map (a: ''-L ${a}/lib'') [
|
||||
# pkgs.libvmi
|
||||
]);
|
||||
# Add libvmi, glibc, clang, glib headers to bindgen search path
|
||||
BINDGEN_EXTRA_CLANG_ARGS =
|
||||
# Includes with normal include path
|
||||
(builtins.map (a: ''-I"${a}/include"'') [
|
||||
# pkgs.libvmi
|
||||
# pkgs.glibc.dev
|
||||
])
|
||||
# Includes with special directory paths
|
||||
++ [
|
||||
''-I"${pkgs.llvmPackages_latest.libclang.lib}/lib/clang/${pkgs.llvmPackages_latest.libclang.version}/include"''
|
||||
''-I"${pkgs.glib.dev}/include/glib-2.0"''
|
||||
''-I${pkgs.glib.out}/lib/glib-2.0/include/''
|
||||
];
|
||||
LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath buildInputs}";
|
||||
|
||||
}
|
104
src/main.rs
Normal file
104
src/main.rs
Normal file
|
@ -0,0 +1,104 @@
|
|||
use std::cell::RefCell;
|
||||
|
||||
use futures::prelude::*;
|
||||
use irc::client::prelude::*;
|
||||
|
||||
use color_eyre::eyre::Result;
|
||||
use iced::theme::Theme;
|
||||
use iced::widget::{container, text};
|
||||
use iced::{executor, Application, Settings};
|
||||
use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender};
|
||||
|
||||
async fn irc_loop(sender: UnboundedSender<irc::proto::Message>) -> Result<()> {
|
||||
let config = Config {
|
||||
nickname: Some("cri".to_string()),
|
||||
server: Some("vijf.life".to_string()),
|
||||
channels: vec!["#h".to_string()],
|
||||
..Config::default()
|
||||
};
|
||||
|
||||
let mut client = Client::from_config(config).await?;
|
||||
client.identify()?;
|
||||
|
||||
let mut stream = client.stream()?;
|
||||
|
||||
while let Some(message) = stream.next().await.transpose()? {
|
||||
sender.send(message)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
color_eyre::install()?;
|
||||
|
||||
let (sender, receiver) = mpsc::unbounded_channel::<irc::proto::Message>();
|
||||
|
||||
tokio::task::spawn(irc_loop(sender));
|
||||
|
||||
Cri::run(Settings::with_flags(CriFlags { receiver }))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
struct Cri {
|
||||
pub receiver: RefCell<Option<UnboundedReceiver<irc::proto::Message>>>,
|
||||
pub irc_message: String,
|
||||
}
|
||||
|
||||
struct CriFlags {
|
||||
pub receiver: UnboundedReceiver<irc::proto::Message>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Message {
|
||||
IrcMessageReceived(irc::proto::Message),
|
||||
}
|
||||
|
||||
impl Application for Cri {
|
||||
type Executor = executor::Default;
|
||||
type Message = Message;
|
||||
type Theme = Theme;
|
||||
type Flags = CriFlags;
|
||||
|
||||
fn new(flags: Self::Flags) -> (Self, iced::Command<Self::Message>) {
|
||||
(
|
||||
Self {
|
||||
receiver: RefCell::new(Some(flags.receiver)),
|
||||
irc_message: String::new(),
|
||||
},
|
||||
iced::Command::none(),
|
||||
)
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
"cri".to_string()
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Self::Message) -> iced::Command<Self::Message> {
|
||||
match message {
|
||||
Message::IrcMessageReceived(message) => {
|
||||
let message = message.to_string().replace("\r", "");
|
||||
self.irc_message += &message;
|
||||
}
|
||||
}
|
||||
iced::Command::none()
|
||||
}
|
||||
|
||||
fn subscription(&self) -> iced::Subscription<Self::Message> {
|
||||
iced::subscription::unfold(
|
||||
"irc message",
|
||||
self.receiver.take(),
|
||||
move |mut receiver| async move {
|
||||
let message = receiver.as_mut().unwrap().recv().await.unwrap();
|
||||
(Message::IrcMessageReceived(message), receiver)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn view(&self) -> iced::Element<'_, Self::Message, iced::Renderer<Self::Theme>> {
|
||||
let log = text(self.irc_message.clone());
|
||||
container(log).into()
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue