Skip to content

Commit

Permalink
Add devcontainer
Browse files Browse the repository at this point in the history
  • Loading branch information
lasantosr committed Mar 18, 2023
1 parent b9f319f commit 13e3149
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 2 deletions.
36 changes: 36 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM rust

# Install clippy and nightly rustfmt
RUN rustup component add clippy
RUN rustup toolchain install nightly
RUN rustup component add rustfmt --toolchain nightly-x86_64-unknown-linux-gnu

# Install some cargo utilities
ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
RUN cargo install cargo-audit
RUN curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin

# Install zsh
RUN apt-get update && apt-get install zsh -y

# Create default non-root user
ARG USERNAME=rust
ARG USER_UID=1000
ARG USER_GID=$USER_UID
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& apt-get install -y sudo \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME \
&& chown -R $USERNAME:$USERNAME /usr/local/cargo \
&& chown -R $USERNAME:$USERNAME /usr/local/rustup
USER $USERNAME

# Source artifact to be ready to execute
RUN echo "\n# Search up & down" >> ~/.bashrc
RUN echo "bind '\"\e[A\": history-search-backward'" >> ~/.bashrc
RUN echo "bind '\"\e[B\": history-search-forward'" >> ~/.bashrc
RUN echo "\n# IntelliShell debug" >> ~/.bashrc
RUN echo "alias intelli-shell=/workspaces/intelli-shell/target/debug/intelli-shell" >> ~/.bashrc
RUN echo "source /workspaces/intelli-shell/intelli-shell.sh" >> ~/.bashrc
RUN echo "alias ll='ls -alF'" >> ~/.bashrc
31 changes: 31 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "Rust Codespace",
"dockerFile": "Dockerfile",
"postCreateCommand": "cargo build",
"customizations": {
"vscode": {
"extensions": [
"rust-lang.rust-analyzer",
"serayuzgur.crates",
"tamasfe.even-better-toml",
"vadimcn.vscode-lldb",
"eamodio.gitlens",
"usernamehw.errorlens"
],
"settings": {
"terminal.integrated.defaultProfile.linux": "bash",
"terminal.integrated.profiles.linux": {
"bash": {
"path": "/bin/bash"
},
"zsh": {
"path": "/bin/zsh"
}
},
"files.watcherExclude": {
"**/target/**": true
}
}
}
}
}
1 change: 1 addition & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"rust-lang.rust-analyzer",
"serayuzgur.crates",
"tamasfe.even-better-toml",
"vadimcn.vscode-lldb",
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
Expand Down
16 changes: 14 additions & 2 deletions src/common.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use crossterm::event::{self, Event};
use crossterm::event::{self, Event, KeyCode, KeyModifiers};
use regex::{CaptureMatches, Captures, Regex};
use tui::{backend::Backend, layout::Rect, text::Text, widgets::ListState, Frame, Terminal};
use unicode_width::UnicodeWidthStr;
Expand Down Expand Up @@ -75,12 +75,24 @@ pub trait Widget {
Self: Sized,
{
loop {
// Draw UI
terminal.draw(|f| {
let area = area(f);
self.render(f, area, inline, theme);
})?;

if let Some(res) = self.process_event(event::read()?)? {
// Exit on Ctrl+C
let event = event::read()?;
if let Event::Key(k) = &event {
if let KeyCode::Char(c) = k.code {
if c == 'c' && k.modifiers.contains(KeyModifiers::CONTROL) {
return Ok(WidgetOutput::empty());
}
}
}

// Process event by widget
if let Some(res) = self.process_event(event)? {
return Ok(res);
}
}
Expand Down

0 comments on commit 13e3149

Please sign in to comment.