Hello everyone!
I am working on a project called Alien Code, which is an ecosystem that helps building software and making software engineering. You can check the previous link if you want a better description of the project. Here, the focus will be the problem I am currently facing in my prototype.
Context
ContentSnapshot struct
I have a struct called ContentSnapshot, which stores the rust source code related to a main function:
// Imagine a main function like this:
fn main(){
// This would be the body of the main function
/* <ContentSnapshot>.source_code represents this body */
}
The definition of the struct is:
#[derive(Debug)]
struct ContentSnapshot {
source_code: String,
commit_message: String,
timestamp: DateTime<Utc>,
author: String,
}
Basically I am storing this source code (source_code) as a String.
TUI interface with cursive
I am also implementing a TUI (Terminal User Interface) using cursive crate for this software because I want the user to be able to edit the source code. I am currently using TextArea
element to add and edit the source code. For the prototype purpose, it is almost reasonable, but, at some moment, I will want this part to be a fullscreen dialog with vim text editor features and rust-analyzer features like we have in vs code.
As you can see, the current state of the application is the following:
- I select the create option:
- I choose the "Main Function" option:
- I enter the necessary information:
- Then, I add the source code of my main function
The Problem
I want to know what would be the best approaches to implement a cursive dialog with vim text editor with rust-analyzer capabilities. What would you do in that situation (even if it is something completely different from my current approach)? Would you implement everything from scratch? If yes, any sources on how to do it? If no, what are the options?
Some approaches I have considered and the problems I have identified in each:
- Build everything from scratch: huge effort, lose the focus on the current prototype, lack of sources that teaches you how to build a text editor, no knowledge of rust compiler yet.
- Use a package that allows the creation of a cursive/tui dialog with vim/rust-analyzer capabilities: I found only cursor, I do not know any other that could help
- Use external editor like vim (I found this to be the most promising approach): how can I give it the granularity I want? For example, in the current problem I want to allow the user only to edit the body of the main. The user will not be able to edit anything else.
This is what I have:
This is what I want:
Thanks in advance. And if you want to contribute with this project, please, contact me.