Skip to content

Commit ef33ae0

Browse files
4.10
1 parent 0add519 commit ef33ae0

File tree

15 files changed

+89
-59
lines changed

15 files changed

+89
-59
lines changed

.github/workflows/rust.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,22 @@ env:
1010
CARGO_TERM_COLOR: always
1111

1212
jobs:
13-
build:
14-
13+
build_ubuntu:
1514
runs-on: ubuntu-latest
1615

1716
steps:
18-
- uses: actions/checkout@v3
19-
- name: Build
17+
- name: Checkout code
18+
uses: actions/checkout@v3
19+
20+
- name: Build on Linux
21+
run: cargo build --release
22+
23+
build_windows:
24+
runs-on: windows-latest
25+
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@v3
29+
30+
- name: Build on Windows
2031
run: cargo build --release

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
欢迎使用 Tiks,一个简易的 Linux 终端命令行工具,类似于常见的 Linux 终端环境,提供了一系列常用的命令和功能。
44
#### 供参考,若有错误改进地方可push到main
55

6-
![Project Logo](images/new.png)
7-
86
## 环境变量
97

108
如果想将其加入环境变量:
119

1210
```bash
1311
Cargo build --release
1412
cp | copy ./target/release/tiks $HOME/.Tiks/bin
13+
或者下载 tiks / tiks.exe
14+
添加至.Tiks目录下的bin中
1515
```
1616

1717
- Windows: 执行./window/setup.bat -> setx PATH "%PATH%;%TIKS_DIR%\bin"
@@ -21,7 +21,7 @@
2121

2222
如果想向其中添加其余函数:
2323

24-
- C: [详见C添加方法](./command/c_build/README.md)
24+
- C\C++: [详见添加方法](./command/c_build/README.md)
2525
- rust: [详间rust添加方法](./command/src/commands/README.md)
2626

2727
## 功能特点

command/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ rpassword = "7.3.0"
2323
libc = "0.2.153"
2424
base64 = "0.22.0"
2525

26-
2726
[target.'cfg(not(target_os = "windows"))'.dependencies]
2827
term_size = "0.3.0"
2928
termion = "3.0.0"
@@ -35,6 +34,9 @@ path = "bin/main.rs"
3534
[build]
3635
target_name = "tiks"
3736

37+
[build-dependencies]
38+
cc = "1.0"
39+
3840
[profile.dev]
3941
panic = "abort"
4042

command/bin/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@
66
// There is some error or other suggestions contact me : [email protected]
77
// Cargo run
88

9-
10-
119
use command::env::init_env;
1210
use command::run::init_shell;
1311
use command::start_logo::start_logo;
1412
use command::root::new_session;
1513

1614
fn main() {
1715
start_logo();
18-
16+
1917
// new user
2018
let mut session_context = new_session();
2119

command/build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main(){
2+
// file: c_build/your.c\
3+
// compile: your function name
4+
cc::Build::new()
5+
.file("");
6+
}

command/c_build/README.md

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,49 @@
33
确保你的系统中存在C/C++环境与gcc工具链
44

55
- 向文件夹c中加入你的c代码后
6-
- chmod +x ./build_c.sh
7-
- Usage: ./build_c.sh <source_file> <output_object_file(.c)> <output_shared_library_file(.so)>
6+
- 见一下代码 [详细的了解cc](https://docs.rs/cc/1.0.92/cc/)
87

98

109
完成后,可在command.rs中声明方法,并在arg.rs中进行配置
1110
详见:[rust添加方法](../src/commands/README.md)
1211

13-
```bash
14-
./build_c.sh vim vim.c vim.so
15-
```
16-
17-
1812
```rust
19-
extern {
20-
fn vim_edit(filename: *const libc::c_char);
13+
14+
//build.rs
15+
// C
16+
fn main() {
17+
cc::Build::new()
18+
.file("foo.c")
19+
.file("bar.c")
20+
.compile("foo");
2121
}
2222

23-
#[link(name = "vim")]
24-
extern {}
23+
// C++
24+
fn main(){
25+
cc::Build::new()
26+
.cpp(true)
27+
.file("foo.cpp")
28+
.compile("foo")
29+
}
30+
31+
// cargo build 后会将以上.c文件编译为libfoo.a
32+
// 如果你的方法中包含有
33+
void foo_function(void) { ... } 和 int32_t bar_function(int32_t x) { ... }
2534

26-
fn main() {
27-
let filename = "example.txt";
35+
36+
extern "C" {
37+
fn foo_function();
38+
fn bar_function(x: i32) -> i32;
39+
}
40+
41+
pub fn call() {
2842
unsafe {
29-
let filename_c = std::ffi::CString::new(filename).expect("CString::new failed");
30-
vim_edit(filename_c.as_ptr());
43+
foo_function();
44+
bar_function(42);
3145
}
3246
}
47+
48+
fn main() {
49+
call();
50+
}
3351
```

command/src/commands/download.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ pub struct Package{
1616
}
1717

1818
// apt install
19+
20+
21+
// upload soon
1922
impl Package{
2023
pub fn new(name: String, version: String, download_link: String) -> Package{
2124
Package{
@@ -58,6 +61,8 @@ async fn download(link: &str, filename: &str) -> Result<(),Box<dyn std::error::E
5861

5962

6063
// apt update new
64+
65+
// upload soon
6166
pub fn update(version: &str) -> std::io::Result<()>{
6267
let mut version = version;
6368
let home = dirs::home_dir().unwrap();

command/src/env/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#[cfg(target_os="linux")]
2-
fn set_env_l() -> (usize,String){
2+
fn set_env() -> (usize,String){
33
use std::{env, path::PathBuf};
44

55
use crate::state_code::env;
@@ -26,7 +26,7 @@ fn set_env_l() -> (usize,String){
2626
}
2727

2828
#[cfg(target_os="windows")]
29-
fn set_env_w() -> (usize,String){
29+
fn set_env() -> (usize,String){
3030
use std::env;
3131
use std::path::PathBuf;
3232

@@ -48,7 +48,7 @@ fn set_env_w() -> (usize,String){
4848

4949
pub fn init_env(){
5050
#[cfg(target_os="windows")]
51-
set_env_w();
51+
set_env();
5252
#[cfg(target_os="linux")]
53-
set_env_l();
53+
set_env();
5454
}

command/src/root.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ impl SessionContext{
132132
}
133133
},
134134
Err(_) =>{
135+
println!("Tiks::welcome-to-try\r\nplease add your account");
135136
#[cfg(target_os="linux")]
136137
init_setup_linux();
137138
#[cfg(target_os="mac")]
@@ -247,9 +248,7 @@ fn init_setup_mac() {
247248

248249
#[cfg(target_os="windows")]
249250
fn init_setup_windows() {
250-
Command::new("cmd")
251-
.arg("/C")
252-
.arg("./window/setup.bat")
251+
Command::new("./window/setup.bat")
253252
.spawn()
254253
.expect("Error: Can't setup on Windows");
255254
}

0 commit comments

Comments
 (0)