1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use crate::cx::*;
use std::collections::HashMap;
use std::net::{TcpStream, SocketAddr};
const LIVE_SERVER_DEFAULT_PORT:u16 = 45823;
pub struct LiveClient{
pub colors: HashMap<String, HashMap<(usize,usize), Color>>
}
struct LiveError{
msg:String
}
type LiveResult<T> = Result<T, LiveError>;
impl LiveClient{
pub fn connect_to_live_server(server_address: Option<SocketAddr>) -> Option<LiveClient> {
let addr = if let Some(addr) = server_address{
addr
}
else{
SocketAddr::from(([127, 0, 0, 1], LIVE_SERVER_DEFAULT_PORT))
};
let mut _tcp_stream = if let Ok(stream) = TcpStream::connect(addr) {
stream
}
else {
return None
};
None
}
}
impl Cx{
pub fn pick(&self, file:&str, line:usize, col:usize, inp:Color)->Color{
if let Some(lc) = &self.live_client{
if let Some(colors) = lc.colors.get(file){
if let Some(color) = colors.get(&(line, col)){
return *color
}
}
}
inp
}
}
#[macro_export]
macro_rules!pick {
( $ cx: ident, $col: literal) => {
$cx.pick(file!(), line!(), column!(), color($col))
}
}