Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
talis-fb committed May 8, 2023
2 parents 28f4847 + e619ecb commit b50b258
Show file tree
Hide file tree
Showing 106 changed files with 3,203 additions and 1,158 deletions.
419 changes: 397 additions & 22 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
[package]
name = "treq"
authors = [ "Talis-Fb" ]
version = "0.3.1"
version = "0.4.0"
edition = "2021"
license = "GPL-3.0"
description = "A Client to make HTTP requests for Vim/Terminal Users"
homepage = "https://github.com/talis-fb/TReq"
repository = "https://github.com/talis-fb/TReq"
documentation = "https://github.com/talis-fb/TReq"
documentation = "https://github.com/talis-fb/TReq/wiki"
categories = ["command-line-interface"]
keywords = [
"cli",
"tui",
"http",
"client",
"terminal",
"restful"
]

[dependencies]
tui = "0.19"
Expand All @@ -25,6 +34,8 @@ regex = "1.7.1"
log = "0.4.17"
log4rs = "1.2.0"
tera = "1.18.1"
mockall = "0.11.4"
clap = { version = "4.2.7", features = ["derive"] }

[[bin]]
name = "treq"
Expand Down
15 changes: 11 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
FROM rust:latest
FROM rust:1.68-bullseye

WORKDIR /usr/myapp
RUN apt-get update && apt-get install -y vim

WORKDIR /app
COPY . .

RUN cargo install --path .
RUN cargo build --release

RUN useradd -ms /bin/bash appuser
USER appuser

ENV EDITOR=vim

CMD ["treq"]
CMD ["./target/release/treq"]
53 changes: 22 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,8 @@

# Installation

### Recommended

In any Linux environment, it is possible to download TReq with the [Crates.io](https://crates.io/crates/treq) repository. Using this method requires having [Rust](https://www.rust-lang.org/pt-BR/tools/install) installed.

After Rust is installed, run this command to download and compile Treq:

```sh
cargo install treq
```

This can to take a while, due to needing to compile the project and all of its dependencies.

### Debian, Ubuntu, Linux Mint, PopOS, Zorin
It is possible to download a prebuild .deb file [HERE](https://github.com/talis-fb/TReq/releases). After downloading the .deb file, you can unpackage it with the command below.
It is possible to download a prebuild `.deb` file [HERE](https://github.com/talis-fb/TReq/releases/latest). After downloading the `.deb` file, you can unpackage and install it with the command below.

```sh
$ sudo dpkg -i path_to_file.deb
Expand All @@ -51,31 +39,34 @@ Or, if you use [yay](https://github.com/Jguer/yay) just run...
```sh
$ yay -S treq-bin
```
### Cargo

# Setup

To make use of the full set of feature provided by TReq, the`EDITOR` environment variable needs to be set. TReq will use this variable when opening the text editor.
In any other environment, it is possible to download TReq with the [Crates.io](https://crates.io/crates/treq) repository. Using this method only requires having [Rust](https://www.rust-lang.org/pt-BR/tools/install) installed.

TReq doesn't have a built in way to edit a Body of Requests. It delegates this work to the text editor of your choice. It is recommend you use a terminal text editor like 'vim', 'neovim', 'nano', or even 'emacs' to edit these.
After Rust is installed, run this command to download and compile Treq:

If you do not already have an EDITOR set (to check, type `echo $EDITOR`, into your terminal. The output is the editor that will be used by TReq), you can set up the EDITOR environment variable in a terminal session using the command below. However, after you close the terminal session (window) this configuration will be dropped.
```sh
# instead vim you can use 'code', 'nano', 'emacs', etc..
export EDITOR=vim
cargo install treq
```

To set this up permanent it is necessary to edit your shell configuration. For example:
```sh
# for bash users
echo 'export EDITOR=vim' >> ~/.bashrc
This can to take a while, due to needing to compile the project and all of its dependencies.

# for zsh users
echo 'export EDITOR=vim' >> ~/.zshrc

# for fish users
echo 'export EDITOR=vim' >> ~/.config/fish/config.fish
```
# Setup external editor

TReq uses the`EDITOR` environment variable to open an external text editor when editing the Request's body or header.

TReq doesn't have a built in way to edit a Body of Requests. It delegates this work to the text editor of your choice. It is recommend you use a terminal text editor like 'vim', 'neovim', 'nano', or 'emacs'.

You can also set `TREQ_EDITOR` environment variable. If you want to use a specific editor with TReq. Without overwrite `EDITOR` value.

You can check the [wiki page for a complete guide of editor setup](https://github.com/talis-fb/TReq/wiki/Editor)

# Usage
For a complete and simple guide how to use TReq: https://github.com/talis-fb/TReq/wiki/Usage

# Using variables inside Request

However, it is quite commmon for this editor to already be set, but beware of non-terminal editors being set (like `writer` from LibreOffice Writer), because they will not work smoothly with TReq. It is recommended to use a terminal text editor like _vi_ or _nano_.
It's possible to use variables inside body or header values of a request. You can [check Wiki page for a complete guide of variables usage in TReq](https://github.com/talis-fb/TReq/wiki/Variables)

However, TReq will work fine with some graphical editors, like VS Code or Atom. In these cases, when you hit the command to 'edit body', TReq will open the graphical editor up, and you will need to hit reload the file with 'r' in TReq ever time you make some change.
![showcase-variables](https://res.cloudinary.com/dfjn94vg8/image/upload/v1683563477/TReq/template_1_cuhrp2.gif)
36 changes: 17 additions & 19 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use crate::base::actions::{manager::ActionsManager, Actions};
use crate::base::commands::Command;
use crate::base::os::os_commands::factory::OsCommandFactory;
use crate::base::os::os_commands::OsCommand;
use crate::base::states::manager::StateManager;
use crate::base::states::states::State;
use crate::base::stores::MainStore;
use crate::base::web::client::WebClient;
use crate::base::web::repository::reqwest::ReqwestClientRepository;

use crate::config::configurations::save_files::SaveFiles;
use crate::input::buffer::InputKeyboardBuffer;
use std::sync::mpsc::Sender;
use std::sync::Arc;
use tokio::sync::mpsc::Sender;

#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum InputMode {
Expand All @@ -23,10 +22,11 @@ pub enum InputMode {
pub struct App {
pub is_finished: bool,
pub renderer: Option<Sender<Actions>>,
pub os_commands_queue: Option<Sender<OsCommand>>,
pub os_commands_factory: Option<Box<dyn OsCommandFactory>>,

// Datas
pub data_store: Option<MainStore>,
pub save_files: Option<SaveFiles>,

// States
pub state_manager: Option<StateManager>,
Expand All @@ -35,7 +35,7 @@ pub struct App {
pub action_manager: Option<ActionsManager>,

// Web Client
pub client_web: Option<Arc<WebClient<ReqwestClientRepository>>>,
pub client_web: Option<Arc<WebClient>>,
}

// ---------------------------------------
Expand All @@ -45,21 +45,24 @@ impl App {
pub fn set_data_store(&mut self, data_store: MainStore) {
self.data_store = Some(data_store)
}
pub fn set_save_file(&mut self, save_files: SaveFiles) {
self.save_files = Some(save_files)
}
pub fn set_state_manager(&mut self, state_manager: StateManager) {
self.state_manager = Some(state_manager)
}
pub fn set_action_manager(&mut self, action_manager: ActionsManager) {
self.action_manager = Some(action_manager)
}
pub fn set_web_client(&mut self, client: WebClient<ReqwestClientRepository>) {
pub fn set_web_client(&mut self, client: WebClient) {
self.client_web = Some(Arc::new(client))
}
pub fn set_renderer(&mut self, renderer: Sender<Actions>) {
self.renderer = Some(renderer)
}
pub fn set_os_commands_queue(&mut self, sender: Sender<OsCommand>) {
self.os_commands_queue = Some(sender)
}
pub fn set_os_commands_factory(&mut self, factory: impl OsCommandFactory + 'static) {
self.os_commands_factory = Some(Box::new(factory));
}
}

// -----------------------------------------
Expand All @@ -80,15 +83,7 @@ impl App {
data_store.set_log_input_mode();
self.get_input_buffer_mut().set_value(initial_buffer);
}
pub fn set_vim_mode_with_command(&mut self, callback: Command, initial_buffer: String) {
self.set_mode(InputMode::Vim);
let data_store = self.get_data_store_mut();
data_store.input_buffer.command = callback;

self.get_input_buffer_mut()
.set_backup(initial_buffer.clone());
self.set_input_buffer_value(initial_buffer);
}
pub fn get_input_buffer(&mut self) -> &InputKeyboardBuffer {
&self.get_data_store_mut().input_buffer
}
Expand Down Expand Up @@ -161,6 +156,9 @@ impl App {
}

pub fn rerender(&self) {
self.renderer.as_ref().unwrap().send(Actions::Null).unwrap();
let sender = self.renderer.as_ref().unwrap().clone();
tokio::task::spawn(async move {
sender.send(Actions::Null).await.unwrap();
});
}
}
16 changes: 7 additions & 9 deletions src/base/commands/commands/docs.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use std::sync::Arc;

use crate::app::App;
use crate::app::InputMode;
use crate::base::commands::CommandTrait;
use crate::base::commands::{Command, Commands};
use crate::base::doc::DocsFactory;
use crate::commands::{Command, Commands};
use crate::App;

impl Commands {
pub fn open_help_screen() -> Command {
Expand All @@ -17,7 +15,7 @@ impl Commands {
}
}

Arc::new(Box::new(S {}))
Commands::from(S {})
}

pub fn open_welcome_screen() -> Command {
Expand All @@ -30,7 +28,7 @@ impl Commands {
}
}

Arc::new(Box::new(S {}))
Commands::from(S {})
}

pub fn doc_up() -> Command {
Expand All @@ -49,7 +47,7 @@ impl Commands {
}
}

Arc::new(Box::new(S {}))
Commands::from(S {})
}

pub fn doc_down() -> Command {
Expand All @@ -68,7 +66,7 @@ impl Commands {
}
}

Arc::new(Box::new(S {}))
Commands::from(S {})
}

pub fn doc_exit() -> Command {
Expand All @@ -80,6 +78,6 @@ impl Commands {
}
}

Arc::new(Box::new(S {}))
Commands::from(S {})
}
}
Loading

0 comments on commit b50b258

Please sign in to comment.