mirror of https://git.meli.delivery/meli/meli
Remove ui crate
Merge ui crate with root crate. In preparation for uploading `meli` as a separate crate on crates.io. Workspace crates will need to be published as well and having a separate `ui` crate and binary perhaps doesn't make sense anymore.pull/234/head
parent
6fcc792b83
commit
8b6ea8de9a
@ -1,17 +0,0 @@
|
||||
[package]
|
||||
name = "debug_printer"
|
||||
version = "0.0.1" #:version
|
||||
authors = ["Manos Pitsidianakis <el13635@mail.ntua.gr>"]
|
||||
workspace = ".."
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
name = "debugprinter"
|
||||
crate-type = ["dylib"]
|
||||
path = "src/lib.rs"
|
||||
|
||||
|
||||
[dependencies]
|
||||
libc = {version = "0.2.55", features = ["extra_traits",] }
|
||||
melib = { path = "../melib", version = "*" }
|
||||
ui = { path = "../ui", version = "*" }
|
@ -1,44 +0,0 @@
|
||||
extern crate libc;
|
||||
extern crate melib;
|
||||
|
||||
use melib::Envelope;
|
||||
use std::ffi::CString;
|
||||
use std::os::raw::c_char;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn print_envelope(ptr: *const Envelope) -> *const c_char {
|
||||
unsafe {
|
||||
assert!(!ptr.is_null(), "Null pointer in print_envelope");
|
||||
//println!("got addr {}", p as u64);
|
||||
//unsafe { CString::new("blah".to_string()).unwrap().as_ptr() }
|
||||
let s = CString::new(format!("{:?}", *ptr)).unwrap();
|
||||
drop(ptr);
|
||||
let p = s.as_ptr();
|
||||
std::mem::forget(s);
|
||||
p
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn get_empty_envelope() -> *mut Envelope {
|
||||
let mut ret = Envelope::default();
|
||||
let ptr = std::ptr::NonNull::new(&mut ret as *mut Envelope)
|
||||
.expect("Envelope::default() has a NULL pointer?");
|
||||
|
||||
let ptr = ptr.as_ptr();
|
||||
std::mem::forget(ret);
|
||||
ptr
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn destroy_cstring(ptr: *mut c_char) {
|
||||
unsafe {
|
||||
let slice = CString::from_raw(ptr);
|
||||
drop(slice);
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn envelope_size() -> libc::size_t {
|
||||
std::mem::size_of::<Envelope>()
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* meli - ui crate.
|
||||
* meli
|
||||
*
|
||||
* Copyright 2017-2018 Manos Pitsidianakis
|
||||
*
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* meli - ui crate
|
||||
* meli
|
||||
*
|
||||
* Copyright 2017-2018 Manos Pitsidianakis
|
||||
*
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* meli - ui crate.
|
||||
* meli
|
||||
*
|
||||
* Copyright 2017-2018 Manos Pitsidianakis
|
||||
*
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* meli - ui crate.
|
||||
* meli
|
||||
*
|
||||
* Copyright 2017-2018 Manos Pitsidianakis
|
||||
*
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* meli - ui crate.
|
||||
* meli
|
||||
*
|
||||
* Copyright 2017-2018 Manos Pitsidianakis
|
||||
*
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* meli - ui crate.
|
||||
* meli
|
||||
*
|
||||
* Copyright 2017-2018 Manos Pitsidianakis
|
||||
*
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* meli - ui crate.
|
||||
* meli
|
||||
*
|
||||
* Copyright 2019 Manos Pitsidianakis
|
||||
*
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* meli - ui crate.
|
||||
* meli
|
||||
*
|
||||
* Copyright 2017-2018 Manos Pitsidianakis
|
||||
*
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* meli - ui crate.
|
||||
* meli
|
||||
*
|
||||
* Copyright 2017-2018 Manos Pitsidianakis
|
||||
*
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* meli - ui crate.
|
||||
* meli
|
||||
*
|
||||
* Copyright 2017-2018 Manos Pitsidianakis
|
||||
*
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* meli - ui crate.
|
||||
* meli
|
||||
*
|
||||
* Copyright 2017-2018 Manos Pitsidianakis
|
||||
*
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* meli - ui crate.
|
||||
* meli
|
||||
*
|
||||
* Copyright 2017-2018 Manos Pitsidianakis
|
||||
*
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* meli - ui crate.
|
||||
* meli
|
||||
*
|
||||
* Copyright 2017-2018 Manos Pitsidianakis
|
||||
*
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* meli - ui crate.
|
||||
* meli
|
||||
*
|
||||
* Copyright 2017-2020 Manos Pitsidianakis
|
||||
*
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* meli - ui crate.
|
||||
* meli
|
||||
*
|
||||
* Copyright 2017-2018 Manos Pitsidianakis
|
||||
*
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* meli - ui crate.
|
||||
* meli
|
||||
*
|
||||
* Copyright 2019 Manos Pitsidianakis
|
||||
*
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* meli - ui crate.
|
||||
* meli
|
||||
*
|
||||
* Copyright 2017-2020 Manos Pitsidianakis
|
||||
*
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* meli - ui crate.
|
||||
* meli
|
||||
*
|
||||
* Copyright 2017-2020 Manos Pitsidianakis
|
||||
*
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* meli - ui crate.
|
||||
* meli
|
||||
*
|
||||
* Copyright 2017-2018 Manos Pitsidianakis
|
||||
*
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* meli - ui crate.
|
||||
* meli
|
||||
*
|
||||
* Copyright 2017-2020 Manos Pitsidianakis
|
||||
*
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* meli - ui crate.
|
||||
* meli
|
||||
*
|
||||
* Copyright 2017-2018 Manos Pitsidianakis
|
||||
*
|
@ -1,41 +0,0 @@
|
||||
[package]
|
||||
name = "ui"
|
||||
version = "0.4.1"
|
||||
authors = ["Manos Pitsidianakis <el13635@mail.ntua.gr>"]
|
||||
workspace = ".."
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
xdg = "2.1.0" # >:c
|
||||
serde = "1.0.71"
|
||||
serde_derive = "1.0.71"
|
||||
serde_json = "1.0"
|
||||
toml = "0.5.3"
|
||||
crossbeam = "0.7.2"
|
||||
fnv = "1.0.3" # >:c
|
||||
linkify = "0.3.1" # >:c
|
||||
melib = { path = "../melib", version = "*" }
|
||||
xdg-utils = "0.3.0"
|
||||
nom = "3.2.0"
|
||||
notify = "4.0.1" # >:c
|
||||
notify-rust = "^3" # >:c
|
||||
termion = "1.5.1"
|
||||
bincode = "1.2.0"
|
||||
uuid = { version = "0.7.4", features = ["serde", "v4"] }
|
||||
unicode-segmentation = "1.2.1" # >:c
|
||||
text_processing = { path = "../text_processing", version = "*" }
|
||||
libc = {version = "0.2.59", features = ["extra_traits",]}
|
||||
nix = "0.16.1"
|
||||
rusqlite = {version = "0.20.0", optional =true }
|
||||
rmp = "^0.8"
|
||||
rmpv = { version = "^0.4.2", features=["with-serde",] }
|
||||
rmp-serde = "^0.14.0"
|
||||
smallvec = { version = "1.1.0", features = ["serde", ] }
|
||||
|
||||
[features]
|
||||
default = ["sqlite3"]
|
||||
notmuch = []
|
||||
sqlite3 = ["rusqlite"]
|
||||
|
||||
# Print tracing logs as meli runs
|
||||
debug-tracing = []
|
@ -1,134 +0,0 @@
|
||||
/*
|
||||
* meli - ui crate.
|
||||
*
|
||||
* Copyright 2017-2018 Manos Pitsidianakis
|
||||
*
|
||||
* This file is part of meli.
|
||||
*
|
||||
* meli is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* meli is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with meli. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*! Entities that handle Mail specific functions.
|
||||
*/
|
||||
use super::*;
|
||||
|
||||
pub mod index;
|
||||
pub use self::index::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct MenuEntry {
|
||||
name: String,
|
||||
subentries: Vec<MenuEntry>,
|
||||
index: Index,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Indexer {
|
||||
entries: Vec<MenuEntry>,
|
||||
dirty: bool,
|
||||
cursor: Vec<usize>,
|
||||
id: ComponentId,
|
||||
}
|
||||
|
||||
impl fmt::Display for Indexer {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
// TODO display subject/info
|
||||
write!(f, "index")
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Indexer {
|
||||
fn default() -> Self {
|
||||
Indexer {
|
||||
entries: Vec::with_capacity(8),
|
||||
dirty: true,
|
||||
cursor: Vec::with_capacity(8),
|
||||
id: ComponentId::new_v4(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Indexer {
|
||||
fn draw_menu(&mut self, _grid: &mut CellBuffer, _area: Area, _context: &mut Context) {}
|
||||
}
|
||||
|
||||
impl Component for Indexer {
|
||||
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
|
||||
if !self.is_dirty() {
|
||||
return;
|
||||
}
|
||||
|
||||
clear_area(grid, area);
|
||||
let upper_left = upper_left!(area);
|
||||
let bottom_right = bottom_right!(area);
|
||||
|
||||
let total_cols = get_x(bottom_right) - get_x(upper_left);
|
||||
let index_entity_width = (30 * total_cols) / 100;
|
||||
let mid = get_x(bottom_right) - index_entity_width;
|
||||
for i in get_y(upper_left)..=get_y(bottom_right) {
|
||||
set_and_join_box(grid, (mid, i), BoxBoundary::Vertical);
|
||||
}
|
||||
|
||||
let left_menu_area = (upper_left, (set_x(bottom_right, mid - 1)));
|
||||
let right_index_area = (set_x(upper_left, mid + 1), bottom_right);
|
||||
|
||||
self.draw_menu(grid, left_menu_area, context);
|
||||
self.entries[self.cursor[0]]
|
||||
.index
|
||||
.draw(grid, right_index_area, context);
|
||||
|
||||
self.dirty = false;
|
||||
context.dirty_areas.push_back(area);
|
||||
}
|
||||
|
||||
fn process_event(&mut self, event: &mut UIEvent, _context: &mut Context) -> bool {
|
||||
if !self.entries[self.cursor[0]]
|
||||
.index
|
||||
.process_event(event, _context)
|
||||
{
|
||||
for i in 0..self.entries.len() {
|
||||
if i == self.cursor[0] {
|
||||
continue;
|
||||
}
|
||||
self.entries[i].index.process_event(event, _context);
|
||||
}
|
||||
}
|
||||
|
||||
match *event {
|
||||
UIEvent::ChangeMode(UIMode::Normal) => {
|
||||
self.dirty = true;
|
||||
}
|
||||
UIEvent::Resize => {
|
||||
self.dirty = true;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
fn is_dirty(&self) -> bool {
|
||||
self.dirty
|
||||
}
|
||||
|
||||
fn set_dirty(&mut self, value: bool) {
|
||||
self.dirty = value;
|
||||
}
|
||||
|
||||
fn id(&self) -> ComponentId {
|
||||
self.id
|
||||
}
|
||||
fn set_id(&mut self, id: ComponentId) {
|
||||
self.id = id;
|
||||
}
|
||||
}
|
@ -1,185 +0,0 @@
|
||||
use super::*;
|
||||
|
||||
pub trait IndexContent: Component {
|
||||
/* Handles the drawing of one entry */
|
||||
fn make_entry(&mut self, idx: usize) -> ();
|
||||
|
||||
/* Handles what happens when the user selects an entry in the index listing */
|
||||
fn enter_entry(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) -> ();
|
||||
|
||||
/* Refreshes content */
|
||||
fn refresh(&mut self, context: &mut Context) -> ();
|
||||
|
||||
fn search(&self, term: &str) -> Option<usize>;
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
enum IndexState {
|
||||
//Uninitialized,
|
||||
Listing,
|
||||
Unfocused,
|
||||
//Search,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Index {
|
||||
cursor_pos: usize,
|
||||
new_cursor_pos: usize,
|
||||
length: usize,
|
||||
|
||||
/// Cache current view.
|
||||
canvas: CellBuffer,
|
||||
/// If we must redraw on next redraw event
|
||||
dirty: bool,
|
||||
state: IndexState,
|
||||
|
||||
content: Box<dyn IndexContent>,
|
||||
id: ComponentId,
|
||||
}
|
||||
|
||||
impl Index {
|
||||
fn highlight_line(&self, grid: &mut CellBuffer, area: Area, idx: usize) {
|
||||
let fg_color = Color::Default;
|
||||
let bg_color = if self.cursor_pos == idx {
|
||||
Color::Byte(246)
|
||||
/* } else if idx % 2 == 0 {
|
||||
Color::Byte(236)*/
|
||||
} else {
|
||||
Color::Default
|
||||
};
|
||||
change_colors(grid, area, fg_color, bg_color);
|
||||
}
|
||||
}
|
||||
|
||||
impl Component for Index {
|
||||
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
|
||||
if !self.dirty {
|
||||
return;
|
||||
}
|
||||
|
||||
match self.state {
|
||||
IndexState::Listing => {
|
||||
/* rehighlight entries, redraw pages */
|
||||
let upper_left = upper_left!(area);
|
||||
let bottom_right = bottom_right!(area);
|
||||
let rows = get_y(bottom_right) - get_y(upper_left) + 1;
|
||||
let prev_page_no = (self.cursor_pos).wrapping_div(rows);
|
||||
let page_no = (self.new_cursor_pos).wrapping_div(rows);
|
||||
|
||||
let top_idx = page_no * rows;
|
||||
if self.new_cursor_pos >= self.length {
|
||||
self.new_cursor_pos = self.length - 1;
|
||||
}
|
||||
/* If cursor position has changed, remove the highlight from the previous position and
|
||||
* apply it in the new one. */
|
||||
if self.cursor_pos != self.new_cursor_pos && prev_page_no == page_no {
|
||||
let old_cursor_pos = self.cursor_pos;
|
||||
self.cursor_pos = self.new_cursor_pos;
|
||||
for idx in &[old_cursor_pos, self.new_cursor_pos] {
|
||||
if *idx >= self.length {
|
||||
continue; //bounds check
|
||||
}
|
||||
let new_area = (
|
||||
set_y(upper_left, get_y(upper_left) + (*idx % rows)),
|
||||
set_y(bottom_right, get_y(upper_left) + (*idx % rows)),
|
||||
);
|
||||
self.highlight_line(grid, new_area, *idx);
|
||||
context.dirty_areas.push_back(new_area);
|
||||
}
|
||||
return;
|
||||
} else if self.cursor_pos != self.new_cursor_pos {
|
||||
self.cursor_pos = self.new_cursor_pos;
|
||||
}
|
||||
|
||||
/* Page_no has changed, so draw new page */
|
||||
copy_area(
|
||||
grid,
|
||||
&self.canvas,
|
||||
area,
|
||||
((0, top_idx), (500 - 1, self.length)),
|
||||
);
|
||||
self.highlight_line(
|
||||
grid,
|
||||
(
|
||||
(
|
||||
get_x(upper_left),
|
||||
get_y(upper_left) + (self.cursor_pos % rows),
|
||||
),
|
||||
(
|
||||
get_x(bottom_right),
|
||||
get_y(upper_left) + (self.cursor_pos % rows),
|
||||
),
|
||||
),
|
||||
self.cursor_pos,
|
||||
);
|
||||
context.dirty_areas.push_back(area);
|
||||
}
|
||||
IndexState::Unfocused => {
|
||||
self.content.draw(grid, area, context);
|
||||
}
|
||||
}
|
||||
|
||||
self.dirty = false;
|
||||
return;
|
||||
}
|
||||
|
||||
fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool {
|
||||
if self.content.process_event(event, context) {
|
||||
return true;
|
||||
}
|
||||
match *event {
|
||||
UIEvent::Input(Key::Up) => {
|
||||
if self.cursor_pos > 0 {
|
||||
self.new_cursor_pos = self.new_cursor_pos.saturating_sub(1);
|
||||
self.set_dirty(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
UIEvent::Input(Key::Down) => {
|
||||
if self.length > 0 && self.new_cursor_pos < self.length - 1 {
|
||||
self.new_cursor_pos += 1;
|
||||
self.set_dirty(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
UIEvent::Input(Key::Char('\n')) if self.state == IndexState::Listing => {
|
||||
self.state = IndexState::Unfocused;
|
||||
self.set_dirty(true);
|
||||
return true;
|
||||
}
|
||||
UIEvent::Input(Key::Char('i')) if self.state == IndexState::Unfocused => {
|
||||
self.state = IndexState::Listing;
|
||||
self.set_dirty(true);
|
||||
return true;
|
||||
}
|
||||
UIEvent::ChangeMode(UIMode::Normal) => {
|
||||
self.set_dirty(true);
|
||||
}
|
||||
UIEvent::Resize => {
|
||||
self.set_dirty(true);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
fn is_dirty(&self) -> bool {
|
||||
self.dirty || self.content.is_dirty()
|
||||
}
|
||||
fn set_dirty(&mut self, value: bool) {
|
||||
self.dirty = value;
|
||||
}
|
||||
|
||||
fn id(&self) -> ComponentId {
|
||||
self.id
|
||||
}
|
||||
fn set_id(&mut self, id: ComponentId) {
|
||||
self.id = id;
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Index {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
Display::fmt(&self.content, f)
|
||||
}
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
#! /usr/bin/env python3
|
||||
"""
|
||||
meli - sample plugin
|
||||
|
||||
Copyright 2019 Manos Pitsidianakis
|
||||
|
||||
This file is part of meli.
|
||||
|
||||
meli is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
meli is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with meli. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
import msgpack
|
||||
import socket
|
||||
import time
|
||||
import struct
|
||||
import json
|
||||
import sys
|
||||
|
||||
|
||||
class IPCError(Exception):
|
||||
pass
|
||||
|
||||
class UnknownMessageClass(IPCError):
|
||||
pass
|
||||
|
||||
class InvalidSerialization(IPCError):
|
||||
pass
|
||||
|
||||
class ConnectionClosed(IPCError):
|
||||
pass
|
||||
|
||||
|
||||
def _read_objects(sock):
|
||||
unpacker = msgpack.Unpacker()
|
||||
ret = []
|
||||
#reader = socket.socket.makefile(sock, 'rb')
|
||||
while True:
|
||||
try:
|
||||
buf = sock.recv(1024**2)
|
||||
if not buf:
|
||||
break
|
||||
unpacker.feed(buf)
|
||||
for o in unpacker:
|
||||
ret.append(o)
|
||||
except:
|
||||
break
|
||||
return ret
|
||||
|
||||
#try:
|
||||
# for unpack in unpacker:
|
||||
# return unpack
|
||||
#except Exception as e:
|
||||
# print("_read_objects error ", e, file=sys.stderr,)
|
||||
# return None
|
||||
#finally:
|
||||
# reader.flush()
|
||||
|
||||
def _write_objects(sock, objects):
|
||||
data = msgpack.packb(objects)
|
||||
sock.sendall(data)
|
||||
|
||||
def _recursive_subclasses(cls):
|
||||
classmap = {}
|
||||
for subcls in cls.__subclasses__():
|
||||
classmap[subcls.__name__] = subcls
|
||||
classmap.update(_recursive_subclasses(subcls))
|
||||
return classmap
|
||||
|
||||
|
||||
class Client(object):
|
||||
def __init__(self, server_address):
|
||||
self.addr = server_address
|
||||
if isinstance(self.addr, str):
|
||||
address_family = socket.AF_UNIX
|
||||
else:
|
||||
address_family = socket.AF_INET
|
||||
self.sock = socket.socket(address_family, socket.SOCK_STREAM)
|
||||
self.sock.setblocking(0)
|
||||
|
||||
def connect(self):
|
||||
try:
|
||||
self.sock.connect(self.addr)
|
||||
print("connected", file=sys.stderr)
|
||||
except socket.error as msg:
|
||||
print(msg,file=sys.stderr, )
|
||||
sys.exit(1)
|
||||
|
||||
def close(self):
|
||||
self.sock.close()
|
||||
|
||||
def __enter__(self):
|
||||
self.connect()
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
self.close()
|
||||
|
||||
def send(self, objects):
|
||||
_write_objects(self.sock, objects)
|
||||
print("wrote object ", objects, file=sys.stderr)
|
||||
return self.read()
|
||||
|
||||
def read(self):
|
||||
return _read_objects(self.sock)
|
||||
|
||||
if __name__ == "__main__":
|
||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
server_address = './soworkfile'
|
||||
client = Client(server_address)
|
||||
client.connect()
|
||||
client.send({ "version": "dev" })
|
||||
counter = 0
|
||||
try:
|
||||
while True:
|
||||
message = "This is the message. And this is the well {}.".format(counter)
|
||||
counter += 1
|
||||
time.sleep(0.05)
|
||||
print('sending {!r}'.format(message),file=sys.stderr, )
|
||||
print('returned :', client.send(message), file=sys.stderr,)
|
||||
except Exception as msg:
|
||||
print(msg, file=sys.stderr,)
|
||||
|
Loading…
Reference in New Issue