part way there, but can't get ui events to receive properly and don't get events yet

macos-click-through
Keith Simmons 5 years ago
parent ca1fdfc25c
commit 73875eb486

275
Cargo.lock generated

@ -62,6 +62,12 @@ dependencies = [
"num-traits",
]
[[package]]
name = "arc-swap"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7b8a9123b8027467bce0099fe556c628a53c8d83df0507084c31e9ba2e39aff"
[[package]]
name = "arrayref"
version = "0.3.5"
@ -92,6 +98,17 @@ dependencies = [
"shared_library",
]
[[package]]
name = "async-trait"
version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8df72488e87761e772f14ae0c2480396810e51b2c2ade912f97f0f7e5b95e3c"
dependencies = [
"proc-macro2 1.0.7",
"quote 1.0.2",
"syn 1.0.13",
]
[[package]]
name = "atk-sys"
version = "0.6.0"
@ -107,10 +124,11 @@ dependencies = [
[[package]]
name = "atty"
version = "0.2.13"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi 0.3.8",
]
@ -121,11 +139,17 @@ version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2"
[[package]]
name = "autocfg"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
[[package]]
name = "backtrace"
version = "0.3.40"
version = "0.3.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "924c76597f0d9ca25d762c25a4d369d51267536465dc5064bdf0eb073ed477ea"
checksum = "b4b1549d804b6c73f4817df2ba073709e96e426f12987127c48e6745568c350b"
dependencies = [
"backtrace-sys",
"cfg-if",
@ -184,9 +208,9 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "blake2b_simd"
version = "0.5.9"
version = "0.5.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b83b7baab1e671718d78204225800d6b170e648188ac7dc992e9d6bddf87d0c0"
checksum = "d8fb2d74254a3a0b5cac33ac9f8ed0e44aa50378d9dbb2e5d83bd21ed1dc2c8a"
dependencies = [
"arrayref",
"arrayvec 0.5.1",
@ -205,6 +229,12 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5"
[[package]]
name = "bytes"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10004c15deb332055f7a4a208190aed362cf9a7c2f6ab70a305fba50e1105f38"
[[package]]
name = "c2-chacha"
version = "0.2.3"
@ -257,9 +287,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.0.48"
version = "1.0.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f52a465a666ca3d838ebbf08b241383421412fe7ebb463527bba275526d89f76"
checksum = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd"
[[package]]
name = "cexpr"
@ -363,9 +393,9 @@ dependencies = [
[[package]]
name = "constant_time_eq"
version = "0.1.4"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "995a44c877f9212528ccc74b21a232f66ad69001e40ede5bcee2ac9ef2657120"
checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
[[package]]
name = "core-foundation"
@ -445,7 +475,7 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5064ebdbf05ce3cb95e45c8b086f72263f4166b29b97f6baff7ef7fe047b55ac"
dependencies = [
"autocfg",
"autocfg 0.1.7",
"cfg-if",
"crossbeam-utils 0.7.0",
"lazy_static",
@ -479,7 +509,7 @@ version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce446db02cdc3165b94ae73111e570793400d0794e46125cc4056c81cbb039f4"
dependencies = [
"autocfg",
"autocfg 0.1.7",
"cfg-if",
"lazy_static",
]
@ -501,9 +531,9 @@ dependencies = [
[[package]]
name = "curl-sys"
version = "0.4.24"
version = "0.4.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f659f3ffac9582d6177bb86d1d2aa649f4eb9d0d4de9d03ccc08b402832ea340"
checksum = "0c38ca47d60b86d0cc9d42caa90a0885669c2abc9791f871c81f58cdf39e979b"
dependencies = [
"cc",
"libc",
@ -668,6 +698,12 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7bad48618fdb549078c333a7a8528acb57af271d0433bdecd523eb620628364e"
[[package]]
name = "fnv"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
[[package]]
name = "font-kit"
version = "0.4.0"
@ -807,9 +843,9 @@ dependencies = [
[[package]]
name = "getrandom"
version = "0.1.13"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7db7ca94ed4cd01190ceee0d8a8052f08a247aa1b469a7f68c6a3b71afcf407"
checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb"
dependencies = [
"cfg-if",
"libc",
@ -951,11 +987,11 @@ dependencies = [
[[package]]
name = "harfbuzz-sys"
version = "0.3.3"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf14b85a0c906ef4ef3ff87d0fba25ee45b724404a1a3100dc25eeb4f37ff43b"
checksum = "212d74cab8498b2d15700b694fb38f77562869d05e1f8b602dd05221a1ca2d63"
dependencies = [
"cmake",
"cc",
"core-graphics",
"core-text",
"foreign-types",
@ -970,7 +1006,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e6073d0ca812575946eb5f35ff68dbe519907b25c42530389ff946dc84c6ead"
dependencies = [
"ahash",
"autocfg",
"autocfg 0.1.7",
]
[[package]]
@ -1002,9 +1038,9 @@ dependencies = [
[[package]]
name = "image"
version = "0.22.3"
version = "0.22.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b4be8aaefbe7545dc42ae925afb55a0098f226a3fe5ef721872806f44f57826"
checksum = "53cb19c4e35102e5c6fb9ade5e0e236c5588424dc171a849af3141bf0b47768a"
dependencies = [
"byteorder",
"gif",
@ -1118,9 +1154,9 @@ dependencies = [
[[package]]
name = "lock_api"
version = "0.3.2"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e57b3997725d2b60dbec1297f6c2e2957cc383db1cebd6be812163f969c7d586"
checksum = "79b2de95ecb4691949fea4716ca53cdbcfccb2c612e19644a8bad05edcf9f47b"
dependencies = [
"scopeguard",
]
@ -1186,9 +1222,9 @@ checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00"
[[package]]
name = "memchr"
version = "2.2.1"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e"
checksum = "3197e20c7edb283f87c071ddfc7a2cca8f8e0b888c242959846a6fce03c72223"
[[package]]
name = "memmap"
@ -1246,7 +1282,7 @@ dependencies = [
"kernel32-sys",
"libc",
"log",
"miow",
"miow 0.2.1",
"net2",
"slab",
"winapi 0.2.8",
@ -1264,6 +1300,29 @@ dependencies = [
"slab",
]
[[package]]
name = "mio-named-pipes"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5e374eff525ce1c5b7687c4cef63943e7686524a387933ad27ca7ec43779cb3"
dependencies = [
"log",
"mio",
"miow 0.3.3",
"winapi 0.3.8",
]
[[package]]
name = "mio-uds"
version = "0.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125"
dependencies = [
"iovec",
"libc",
"mio",
]
[[package]]
name = "miow"
version = "0.2.1"
@ -1276,6 +1335,16 @@ dependencies = [
"ws2_32-sys",
]
[[package]]
name = "miow"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "396aa0f2003d7df8395cb93e09871561ccc3e785f0acb369170e8cc74ddf9226"
dependencies = [
"socket2",
"winapi 0.3.8",
]
[[package]]
name = "msgbox"
version = "0.4.0"
@ -1292,6 +1361,7 @@ dependencies = [
name = "neovide"
version = "0.1.0"
dependencies = [
"async-trait",
"derive-new",
"env_logger",
"euclid",
@ -1300,10 +1370,12 @@ dependencies = [
"lru",
"msgbox",
"neovim-lib",
"nvim-rs",
"rmpv",
"rust-embed",
"skribo",
"skulpin",
"tokio",
"winres",
]
@ -1370,43 +1442,43 @@ dependencies = [
[[package]]
name = "num-integer"
version = "0.1.41"
version = "0.1.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09"
checksum = "3f6ea62e9d81a77cd3ee9a2a5b9b609447857f3d358704331e4ef39eb247fcba"
dependencies = [
"autocfg",
"autocfg 1.0.0",
"num-traits",
]
[[package]]
name = "num-iter"
version = "0.1.39"
version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76bd5272412d173d6bf9afdf98db8612bbabc9a7a830b7bfc9c188911716132e"
checksum = "dfb0800a0291891dd9f4fe7bd9c19384f98f7fbe0cd0f39a2c6b88b9868bbc00"
dependencies = [
"autocfg",
"autocfg 1.0.0",
"num-integer",
"num-traits",
]
[[package]]
name = "num-rational"
version = "0.2.2"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2885278d5fe2adc2f75ced642d52d879bffaceb5a2e0b1d4309ffdfb239b454"
checksum = "da4dc79f9e6c81bef96148c8f6b8e72ad4541caa4a24373e900a36da07de03a3"
dependencies = [
"autocfg",
"autocfg 1.0.0",
"num-integer",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.10"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4c81ffc11c212fa327657cb19dd85eb7419e163b5b076bede2bdb5c974c07e4"
checksum = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096"
dependencies = [
"autocfg",
"autocfg 1.0.0",
]
[[package]]
@ -1419,6 +1491,20 @@ dependencies = [
"libc",
]
[[package]]
name = "nvim-rs"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24f920d183863ab5de29bf953921b286dc5d214620f385e1bfed82a2b0ec6f44"
dependencies = [
"async-trait",
"log",
"rmp",
"rmpv",
"tokio",
"unix_socket",
]
[[package]]
name = "objc"
version = "0.2.7"
@ -1450,7 +1536,7 @@ version = "0.9.53"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "465d16ae7fc0e313318f7de5cecf57b2fbe7511fd213978b457e1c96ff46736f"
dependencies = [
"autocfg",
"autocfg 0.1.7",
"cc",
"libc",
"pkg-config",
@ -1529,6 +1615,12 @@ version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
[[package]]
name = "pin-project-lite"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8822eb8bb72452f038ebf6048efa02c3fe22bf83f76519c9583e47fc194a422"
[[package]]
name = "pkg-config"
version = "0.3.17"
@ -1608,12 +1700,11 @@ dependencies = [
[[package]]
name = "rand"
version = "0.7.2"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ae1b169243eaf61759b8475a998f0a385e42042370f3a7dbaf35246eacc8412"
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
dependencies = [
"getrandom",
"libc",
"rand_chacha",
"rand_core 0.5.1",
"rand_hc",
@ -1738,9 +1829,9 @@ dependencies = [
[[package]]
name = "regex"
version = "1.3.1"
version = "1.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc220bd33bdce8f093101afe22a037b8eb0e5af33592e6a9caafff0d4cb81cbd"
checksum = "b5508c1941e4e7cb19965abef075d35a9a8b5cdf0846f30b4050e9b55dc55e87"
dependencies = [
"aho-corasick",
"memchr",
@ -1750,9 +1841,9 @@ dependencies = [
[[package]]
name = "regex-syntax"
version = "0.6.12"
version = "0.6.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716"
checksum = "e734e891f5b408a29efbf8309e656876276f49ab6a6ac208600b4419bd893d90"
[[package]]
name = "rmp"
@ -1872,9 +1963,9 @@ checksum = "bfa8506c1de11c9c4e4c38863ccbe02a305c8188e85a05a784c9e11e1c3910c8"
[[package]]
name = "same-file"
version = "1.0.5"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "585e8ddcedc187886a30fa705c47985c3fa88d06624095856b36ca0b82ff4421"
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
dependencies = [
"winapi-util",
]
@ -1989,11 +2080,21 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2"
[[package]]
name = "signal-hook-registry"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94f478ede9f64724c5d173d7bb56099ec3e2d9fc2774aac65d34b8b890405f41"
dependencies = [
"arc-swap",
"libc",
]
[[package]]
name = "skia-bindings"
version = "0.23.0"
version = "0.23.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8205511fbd62dad726b7f815f7365b667158e152a1d745625de0b0b359f8385c"
checksum = "d2d508b4299a1ec465efff0ee446027e9d1faf9cbe6f175bf9bc7e833cce599b"
dependencies = [
"bindgen",
"cc",
@ -2008,9 +2109,9 @@ dependencies = [
[[package]]
name = "skia-safe"
version = "0.23.0"
version = "0.23.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11e07db3343b213531316c18f8be16e540ef3f5bbda794a3aac0f3226ce9d23d"
checksum = "24aed501f0ec23d877de2066c8f1d0680ff29b11a51da6f2dcbfafc0be2c6fde"
dependencies = [
"bitflags",
"lazy_static",
@ -2032,9 +2133,9 @@ dependencies = [
[[package]]
name = "skulpin"
version = "0.5.0"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b73dfb92c679296809e97938b7abed2ef9d908de9b5a98da671b265891617f83"
checksum = "05fe5761e1abdb580a9255255f2cdb41382263e2fd3e5e03e681e5486f8b4f58"
dependencies = [
"ash",
"cocoa",
@ -2150,11 +2251,11 @@ dependencies = [
[[package]]
name = "termcolor"
version = "1.0.5"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96d6098003bde162e4277c70665bd87c326f5a0c3f3fbfb285787fa482d54e6e"
checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f"
dependencies = [
"wincolor",
"winapi-util",
]
[[package]]
@ -2168,9 +2269,9 @@ dependencies = [
[[package]]
name = "thread_local"
version = "0.3.6"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
dependencies = [
"lazy_static",
]
@ -2187,6 +2288,38 @@ dependencies = [
"num-traits",
]
[[package]]
name = "tokio"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffa2fdcfa937b20cb3c822a635ceecd5fc1a27a6a474527e5516aa24b8c8820a"
dependencies = [
"bytes",
"fnv",
"iovec",
"lazy_static",
"libc",
"memchr",
"mio",
"mio-named-pipes",
"mio-uds",
"num_cpus",
"pin-project-lite",
"signal-hook-registry",
"tokio-macros",
"winapi 0.3.8",
]
[[package]]
name = "tokio-macros"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50a61f268a3db2acee8dcab514efc813dc6dbe8a00e86076f935f94304b59a7a"
dependencies = [
"quote 1.0.2",
"syn 1.0.13",
]
[[package]]
name = "toml"
version = "0.5.5"
@ -2265,9 +2398,9 @@ checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
[[package]]
name = "walkdir"
version = "2.2.9"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9658c94fa8b940eab2250bd5a457f9c48b748420d71293b165c8cdbe2f55f71e"
checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d"
dependencies = [
"same-file",
"winapi 0.3.8",
@ -2276,9 +2409,9 @@ dependencies = [
[[package]]
name = "wasi"
version = "0.7.0"
version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d"
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "wayland-client"
@ -2379,9 +2512,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.2"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9"
checksum = "4ccfbf554c6ad11084fb7517daca16cfdcaccbdadba4fc336f032a8b12c2ad80"
dependencies = [
"winapi 0.3.8",
]
@ -2392,16 +2525,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "wincolor"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96f5016b18804d24db43cebf3c77269e7569b8954a8464501c216cc5e070eaa9"
dependencies = [
"winapi 0.3.8",
"winapi-util",
]
[[package]]
name = "winit"
version = "0.20.0-alpha6"

@ -16,8 +16,11 @@ env_logger = "0.7.1"
neovim-lib = { git = "https://github.com/daa84/neovim-lib", version = "0.6" }
rmpv = "0.4.2"
msgbox = "0.4.0"
rust-embed= { version = "5.2.0", features = ["debug-embed"] }
rust-embed = { version = "5.2.0", features = ["debug-embed"] }
image = "0.22.3"
nvim-rs = "0.1.0"
tokio = { version = "0.2.9", features = [ "blocking" ] }
async-trait = "0.1.18"
[build-dependencies]
winres = "0.1.11"

@ -581,10 +581,10 @@ pub fn parse_redraw_event(event_value: Value) -> Result<Vec<RedrawEvent>> {
Ok(parsed_events)
}
pub fn parse_neovim_event(event_name: String, events: Vec<Value>) -> Result<Vec<RedrawEvent>> {
pub fn parse_neovim_event(event_name: String, arguments: Vec<Value>) -> Result<Vec<RedrawEvent>> {
let mut resulting_events = Vec::new();
if event_name == "redraw" {
for event in events {
for event in arguments {
resulting_events.append(&mut parse_redraw_event(event)?);
}
} else {

@ -6,21 +6,29 @@ mod window;
mod keybindings;
mod renderer;
mod error_handling;
mod ui_commands;
#[macro_use] extern crate async_trait;
#[macro_use] extern crate derive_new;
#[macro_use] extern crate rust_embed;
use std::process::{Command, Stdio};
use std::sync::{Arc, Mutex};
use std::thread;
use std::process::Stdio;
use std::sync::mpsc::{channel, Receiver, Sender};
use async_trait::async_trait;
use rmpv::Value;
use neovim_lib::{Neovim, NeovimApi, UiAttachOptions, Session};
use nvim_rs::runtime::ChildStdin;
use nvim_rs::{create, Neovim, UiAttachOptions, Handler};
use tokio::process::Command;
use tokio::task::spawn_blocking;
use window::ui_loop;
use editor::Editor;
use events::parse_neovim_event;
use error_handling::ResultPanicExplanation;
use ui_commands::UiCommand;
const INITIAL_WIDTH: u64 = 100;
const INITIAL_HEIGHT: u64 = 50;
@ -44,53 +52,58 @@ fn create_nvim_command() -> Command {
cmd
}
fn start_nvim(editor: Arc<Mutex<Editor>>) -> Neovim {
let mut cmd = create_nvim_command();
struct NeovimHandler(Arc<Mutex<Editor>>);
let mut session = Session::new_child_cmd(&mut cmd)
.unwrap_or_explained_panic("Could not create command", "Could not create neovim process command");
#[async_trait]
impl Handler for NeovimHandler {
type Writer = ChildStdin;
async fn handle_request(&self, event_name: String, arguments: Vec<Value>, neovim: Neovim<ChildStdin>) -> Result<Value, Value> {
dbg!(&event_name);
let parsed_events = parse_neovim_event(event_name, arguments)
.unwrap_or_explained_panic("Could not parse event", "Could not parse event from neovim");
for event in parsed_events {
let mut editor = self.0.lock().unwrap();
editor.handle_redraw_event(event);
}
Ok(Value::Nil)
}
}
#[tokio::main]
async fn start_nvim(editor: Arc<Mutex<Editor>>) -> Sender<UiCommand> {
let (mut nvim, io_handler, _) = create::new_child_cmd(&mut create_nvim_command(), NeovimHandler(editor.clone())).await
.unwrap_or_explained_panic("Could not create nvim process", "Could not locate or start the neovim process");
tokio::spawn(async move {
match io_handler.await {
Err(join_error) => eprintln!("Error joining IO loop: '{}'", join_error),
Ok(Err(error)) => eprintln!("Error: '{}'", error),
Ok(Ok(())) => {}
};
std::process::exit(0);
});
let receiver = session.start_event_loop_channel();
let join_handle = session.take_dispatch_guard();
let mut nvim = Neovim::new(session);
let mut options = UiAttachOptions::new();
options.set_cmdline_external(false);
options.set_messages_external(false);
options.set_linegrid_external(true);
options.set_rgb(true);
nvim.set_var("neovide", Value::Boolean(true));
nvim.ui_attach(INITIAL_WIDTH as i64, INITIAL_HEIGHT as i64, &options)
nvim.set_var("neovide", Value::Boolean(true)).await;
nvim.ui_attach(INITIAL_WIDTH as i64, INITIAL_HEIGHT as i64, &options).await
.unwrap_or_explained_panic("Could not attach.", "Could not attach ui to neovim process");
// Listen to neovim events
thread::spawn(move || {
println!("UI thread spawned");
loop {
let (event_name, events) = receiver.recv()
.unwrap_or_explained_panic("Could not receive event", "Could not recieve event from neovim");
let parsed_events = parse_neovim_event(event_name, events)
.unwrap_or_explained_panic("Could not parse event", "Could not parse event from neovim");
for event in parsed_events {
let mut editor = editor.lock().unwrap();
editor.handle_redraw_event(event);
}
let (mut sender, receiver) = channel::<UiCommand>();
tokio::spawn(async move {
while let Ok(ui_command) = spawn_blocking(|| receiver.recv()).await.unwrap() {
dbg!(&ui_command);
ui_command.execute(&nvim).await;
}
});
// Quit process when nvim exits
thread::spawn(move || {
join_handle.join().expect("Could not join neovim process...");
std::process::exit(0);
});
nvim
sender
}
fn main() {
// env_logger::from_env(LoggerEnv::default().default_filter_or("warn")).init();
let editor = Arc::new(Mutex::new(Editor::new(INITIAL_WIDTH, INITIAL_HEIGHT)));
let nvim = start_nvim(editor.clone());
ui_loop(editor, nvim, (INITIAL_WIDTH, INITIAL_HEIGHT));
let sender = start_nvim(editor.clone());
ui_loop(editor, sender, (INITIAL_WIDTH, INITIAL_HEIGHT));
}

@ -0,0 +1,34 @@
use nvim_rs::Neovim;
use nvim_rs::runtime::ChildStdin;
#[derive(Debug)]
pub enum UiCommand {
Resize { width: i64, height: i64 },
Keyboard(String),
MouseButton { action: String, position: (i64, i64) },
Scroll { direction: String, position: (i64, i64) },
Drag(i64, i64)
}
impl UiCommand {
pub async fn execute(&self, nvim: &Neovim<ChildStdin>) {
match self {
UiCommand::Resize { width, height } =>
nvim.ui_try_resize(*width.max(&10), *height.max(&3)).await
.expect("Resize failed"),
UiCommand::Keyboard(input_command) => {
nvim.input(&input_command).await
.expect("Input failed");
},
UiCommand::MouseButton { action, position: (grid_x, grid_y) } =>
nvim.input_mouse("left", action, "", 0, *grid_y, *grid_x).await
.expect("Mouse Input Failed"),
UiCommand::Scroll { direction, position: (grid_x, grid_y) } =>
nvim.input_mouse("wheel", direction, "", 0, *grid_y, *grid_x).await
.expect("Mouse Scroll Failed"),
UiCommand::Drag(grid_x, grid_y) =>
nvim.input_mouse("left", "drag", "", 0, *grid_y, *grid_x).await
.expect("Mouse Drag Failed")
}
}
}

@ -8,11 +8,12 @@ use skulpin::winit::dpi::LogicalSize;
use skulpin::winit::event::{ElementState, Event, MouseScrollDelta, StartCause, WindowEvent};
use skulpin::winit::event_loop::{ControlFlow, EventLoop};
use skulpin::winit::window::{Icon, WindowBuilder};
use neovim_lib::{Neovim, NeovimApi};
use std::sync::mpsc::Sender;
use crate::editor::Editor;
use crate::keybindings::construct_keybinding_string;
use crate::renderer::Renderer;
use crate::ui_commands::UiCommand;
#[derive(RustEmbed)]
#[folder = "assets/"]
@ -20,17 +21,16 @@ struct Asset;
const EXTRA_LIVE_FRAMES: usize = 10;
fn handle_new_grid_size(new_size: LogicalSize, renderer: &Renderer, nvim: &mut Neovim) {
fn handle_new_grid_size(new_size: LogicalSize, renderer: &Renderer, command_channel: &mut Sender<UiCommand>) {
if new_size.width > 0.0 && new_size.height > 0.0 {
let new_width = ((new_size.width + 1.0) as f32 / renderer.font_width) as u64;
let new_height = ((new_size.height + 1.0) as f32 / renderer.font_height) as u64;
// Add 1 here to make sure resizing doesn't change the grid size on startup
nvim.ui_try_resize((new_width as i64).max(10), (new_height as i64).max(3)).expect("Resize failed");
command_channel.send(UiCommand::Resize { width: new_width as i64, height: new_height as i64 });
}
}
pub fn ui_loop(editor: Arc<Mutex<Editor>>, nvim: Neovim, initial_size: (u64, u64)) {
let mut nvim = nvim;
pub fn ui_loop(editor: Arc<Mutex<Editor>>, mut command_channel: Sender<UiCommand>, initial_size: (u64, u64)) {
let mut renderer = Renderer::new(editor.clone());
let event_loop = EventLoop::<()>::with_user_event();
@ -95,7 +95,7 @@ pub fn ui_loop(editor: Arc<Mutex<Editor>>, nvim: Neovim, initial_size: (u64, u64
event: WindowEvent::Resized(new_size),
..
} => {
handle_new_grid_size(new_size, &renderer, &mut nvim)
handle_new_grid_size(new_size, &renderer, &mut command_channel)
},
Event::WindowEvent {
@ -105,9 +105,9 @@ pub fn ui_loop(editor: Arc<Mutex<Editor>>, nvim: Neovim, initial_size: (u64, u64
},
..
} => {
if let Some(string) = construct_keybinding_string(input) {
nvim.input(&string).expect("Input call failed...");
}
construct_keybinding_string(input)
.map(UiCommand::Keyboard)
.map(|keybinding_string| command_channel.send(keybinding_string));
},
Event::WindowEvent {
@ -121,7 +121,7 @@ pub fn ui_loop(editor: Arc<Mutex<Editor>>, nvim: Neovim, initial_size: (u64, u64
let grid_y = (position.y as f32 / renderer.font_height) as i64;
mouse_pos = (grid_x, grid_y);
if mouse_down {
nvim.input_mouse("left", "drag", "", 0, grid_y, grid_x).expect("Could not send mouse input");
command_channel.send(UiCommand::Drag(grid_y, grid_x));
}
}
@ -143,7 +143,7 @@ pub fn ui_loop(editor: Arc<Mutex<Editor>>, nvim: Neovim, initial_size: (u64, u64
}
};
let (grid_x, grid_y) = mouse_pos;
nvim.input_mouse("left", input_type, "", 0, grid_y, grid_x).expect("Could not send mouse input");
command_channel.send(UiCommand::MouseButton { action: input_type.to_string(), position: (grid_x, grid_y) });
}
Event::WindowEvent {
@ -163,7 +163,7 @@ pub fn ui_loop(editor: Arc<Mutex<Editor>>, nvim: Neovim, initial_size: (u64, u64
if let Some(input_type) = vertical_input_type {
let (grid_x, grid_y) = mouse_pos;
nvim.input_mouse("wheel", input_type, "", 0, grid_y, grid_x).expect("Could not send mouse input");
command_channel.send(UiCommand::Scroll { direction: input_type.to_string(), position: (grid_x, grid_y) });
}
let horizontal_input_type = if horizontal > 0.0 {
@ -176,7 +176,7 @@ pub fn ui_loop(editor: Arc<Mutex<Editor>>, nvim: Neovim, initial_size: (u64, u64
if let Some(input_type) = horizontal_input_type {
let (grid_x, grid_y) = mouse_pos;
nvim.input_mouse("wheel", input_type, "", 0, grid_y, grid_x).expect("Could not send mouse input");
command_channel.send(UiCommand::Scroll { direction: input_type.to_string(), position: (grid_x, grid_y) });
}
}
@ -193,7 +193,7 @@ pub fn ui_loop(editor: Arc<Mutex<Editor>>, nvim: Neovim, initial_size: (u64, u64
}
if draw_result.font_changed {
handle_new_grid_size(window.inner_size(), &renderer, &mut nvim)
handle_new_grid_size(window.inner_size(), &renderer, &mut command_channel)
}
if live_frames > 0 {

Loading…
Cancel
Save