Skip to content

Commit

Permalink
pgsql daemon support
Browse files Browse the repository at this point in the history
  • Loading branch information
Netdex committed Oct 3, 2021
1 parent 13d2bf3 commit 35e95fb
Show file tree
Hide file tree
Showing 21 changed files with 712 additions and 247 deletions.
41 changes: 20 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[patch.crates-io]
imgui = { git = "https://github.com/Netdex/imgui-rs", branch = "hidpi-rounded-fix" }
imgui-sys = { git = "https://github.com/Netdex/imgui-rs", branch = "hidpi-rounded-fix" }
imgui-winit-support = { git = "https://github.com/Netdex/imgui-rs", branch = "hidpi-rounded-fix" }
imgui-glow-renderer = { git = "https://github.com/Netdex/imgui-rs", branch = "hidpi-rounded-fix" }
# imgui-dx9-renderer = { git = "https://github.com/Netdex/imgui-dx9-renderer" }
# imgui-dx11-renderer = { git = "https://github.com/Netdex/imgui-dx11-renderer" }
imgui-dx9-renderer = { path = "../imgui-dx9-renderer" }
imgui-dx11-renderer = { path = "../imgui-dx11-renderer" }
# imgui = { git = "https://github.com/Netdex/imgui-rs", branch = "hidpi-rounded-fix" }
# imgui-sys = { git = "https://github.com/Netdex/imgui-rs", branch = "hidpi-rounded-fix" }
# imgui-winit-support = { git = "https://github.com/Netdex/imgui-rs", branch = "hidpi-rounded-fix" }
# imgui-glow-renderer = { git = "https://github.com/Netdex/imgui-rs", branch = "hidpi-rounded-fix" }
imgui-dx9-renderer = { git = "https://github.com/Netdex/imgui-dx9-renderer" }
imgui-dx11-renderer = { git = "https://github.com/Netdex/imgui-dx11-renderer" }
# imgui-dx9-renderer = { path = "../imgui-dx9-renderer" }
# imgui-dx11-renderer = { path = "../imgui-dx11-renderer" }

[dependencies]
imgui = "0.8.1-alpha.0"
imgui-winit-support = "0.8.1-alpha.0"
imgui = "0.8"
imgui-winit-support = "0.8"
clipboard = "0.5"
imgui-glow-renderer = "0.8.1-alpha.0"
imgui-glow-renderer = "0.8"
glow = "0.10.0"
glutin = "0.27.0"

Expand All @@ -40,6 +40,7 @@ winapi = { version = "0.3", features = [
"d3d9types",
"d3dcompiler",
"d3dcommon",
"jobapi2",
] }
wio = "0.2"
raw-window-handle = "0.3"
Expand All @@ -52,13 +53,12 @@ lazy_static = "1.4.0"
log = "0.4"
env_logger = "0.8.4"


ichiran = { path = "third-party/ichiran" }
imgui-win32-sys = { path = "third-party/imgui-win32-sys" }

[lib]
name = "libniinii"
crate-type = ["cdylib"]
crate-type = ["cdylib", "lib"]

[workspace]
members = ["third-party/ichiran", "third-party/imgui-win32-sys"]
25 changes: 25 additions & 0 deletions res/KanjiStrokeOrders_copyright.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Copyright (C) 2004-2020 Ulrich Apel, the AAAA project and the Wadoku project
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the author may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Binary file added res/KanjiStrokeOrders_v4.004.ttf
Binary file not shown.
49 changes: 42 additions & 7 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::ffi::CString;
use std::process::Command;
use std::sync::mpsc;
use std::thread;

Expand Down Expand Up @@ -44,6 +44,7 @@ pub struct App {

show_imgui_demo: bool,
show_settings: bool,
show_raw: bool,

settings: SettingsView,
state: State,
Expand All @@ -60,11 +61,38 @@ impl App {
last_clipboard: "".into(),
show_imgui_demo: false,
show_settings: false,
show_raw: false,
settings,
state: State::None,
}
}

pub fn start_pg_daemon(&self) {
let ichiran = Ichiran::new(&self.settings.ichiran_path);
let conn_params = ichiran.conn_params();
match conn_params {
Ok(conn_params) => {
log::info!("db conn params: {:?}", conn_params);
let proc = Command::new(&self.settings.postgres_path)
.args([
"-D",
&self.settings.db_path,
"-p",
&format!("{}", conn_params.port),
])
.spawn();
if let Err(err) = &proc {
log::warn!("failed to spawn db daemon: {}", err);
}
proc.ok()
}
Err(err) => {
log::warn!("failed to query db conn params: {}", err);
None
}
};
}

fn request_ast(&mut self, ui: &Ui, text: &str) {
log::trace!("request_ast({})", text);
let ichiran_path = self.settings.ichiran_path.clone();
Expand All @@ -86,7 +114,6 @@ impl App {
}

fn transition(&mut self, ui: &Ui, state: State) {
// log::trace!("transition({:#?})", state);
match &state {
State::Error { .. } => {
ui.open_popup(ERROR_MODAL_TITLE);
Expand Down Expand Up @@ -116,13 +143,18 @@ impl App {

fn show_main_menu(&mut self, _env: &mut Env, ui: &Ui) {
if let Some(_menu_bar) = ui.begin_main_menu_bar() {
if let Some(_menu) = ui.begin_menu("File") {}
if let Some(_menu) = ui.begin_menu("File") {
if MenuItem::new("Quit").build(ui) {}
}
if let Some(_menu) = ui.begin_menu("Edit") {
if MenuItem::new("Settings").build(ui) {
self.show_settings = true;
}
}
if let Some(_menu) = ui.begin_menu("View") {
if MenuItem::new("Show Raw").build(ui) {
self.show_raw = true;
}
if MenuItem::new("ImGui Demo").build(ui) {
self.show_imgui_demo = true;
}
Expand Down Expand Up @@ -155,15 +187,16 @@ impl App {
.size([300.0, 110.0], Condition::FirstUseEver)
.build(ui, || {
{
let trunc = str_from_u8_nul_utf8_unchecked(self.input_text.as_bytes()).to_owned();
let trunc =
str_from_u8_nul_utf8_unchecked(self.input_text.as_bytes()).to_owned();
let _token = ui.begin_disabled(matches!(self.state, State::Processing));
if ui
.input_text_multiline("Text", &mut self.input_text, [0.0, 50.0])
.input_text_multiline("", &mut self.input_text, [0.0, 50.0])
.enter_returns_true(true)
.build()
{
self.requested_text.replace(trunc.clone());
}
let _token = ui.begin_disabled(matches!(self.state, State::Processing));
if ui.button_with_size("Go", [120.0, 0.0]) {
self.requested_text.replace(trunc);
}
Expand All @@ -185,7 +218,7 @@ impl App {
.size([300., 110.], Condition::FirstUseEver)
.build(ui, || match &mut self.state {
State::Displaying { rikai, .. } => {
rikai.ui(env, ui, &self.settings);
rikai.ui(env, ui, &mut self.show_raw);
}
_ => (),
});
Expand All @@ -205,6 +238,8 @@ impl App {
if ui.button_with_size("OK", [120.0, 0.0]) {
self.show_settings = false;
}
ui.same_line();
ui.text("Restart to apply all changes.");
});
}

Expand Down
Loading

0 comments on commit 35e95fb

Please sign in to comment.