This document provides practical examples of using Rust TUI Coder for various development tasks.
- Basic File Operations
- Code Generation
- Refactoring Code
- Debugging Assistance
- Project Setup
- Testing
- Documentation
- Git Workflows
- Data Processing
- Advanced Workflows
User:
Create a README.md file with a title "My Project" and a brief description
What happens:
- AI writes content
- Saves to README.md
- Confirms creation
Result:
# My Project
A brief description of what this project does.User:
Read the file src/main.rs and tell me what it does
What happens:
- AI reads the file using
read_filetool - Analyzes the code
- Explains functionality
User:
In config.toml, change the model_name from gpt-3.5-turbo to gpt-4
What happens:
- AI reads config.toml
- Uses
search_and_replacetool - Updates the model name
- Confirms the change
User:
Create a Python script that reads a CSV file and calculates the average of the 'price' column
What happens:
# average_price.py
import csv
def calculate_average_price(filename):
total = 0
count = 0
with open(filename, 'r') as file:
reader = csv.DictReader(file)
for row in reader:
total += float(row['price'])
count += 1
return total / count if count > 0 else 0
if __name__ == "__main__":
avg = calculate_average_price('data.csv')
print(f"Average price: ${avg:.2f}")- AI generates the code
- Saves to
average_price.py - Explains usage
User:
Create a Node.js Express endpoint that handles POST requests to /users and saves the data to a JSON file
What happens:
// server.js
const express = require('express');
const fs = require('fs');
const app = express();
app.use(express.json());
app.post('/users', (req, res) => {
const userData = req.body;
const users = JSON.parse(fs.readFileSync('users.json', 'utf8') || '[]');
users.push(userData);
fs.writeFileSync('users.json', JSON.stringify(users, null, 2));
res.status(201).json({ message: 'User created', user: userData });
});
app.listen(3000, () => console.log('Server running on port 3000'));User:
Create unit tests for the calculate_average_price function using pytest
What happens:
- AI creates
test_average_price.py - Includes multiple test cases
- Tests edge cases (empty file, invalid data, etc.)
User:
Read server.js and extract the user validation logic into a separate function
What happens:
- AI reads the file
- Identifies validation code
- Creates new function
- Updates calls to use new function
- Shows the refactored code
User:
Add try-catch error handling to all file operations in backup.py
What happens:
- AI reads the file
- Identifies file operations
- Adds appropriate error handling
- Updates the file
User:
Convert the callback-based code in api.js to use async/await
What happens:
- AI reads the file
- Converts callbacks to promises
- Uses async/await syntax
- Updates the file
User:
This function is giving wrong results. Can you help?
def calculate_discount(price, percent):
discount = price * percent
return price - discount
AI Response:
The bug is that you're using the percentage as a decimal multiplier without dividing by 100.
Fixed version:
def calculate_discount(price, percent):
discount = price * (percent / 100)
return price - discount
Example: calculate_discount(100, 20) now correctly returns 80
User:
Add debug logging to process_data.py to help track down where it's failing
What happens:
- AI adds logging statements
- Includes relevant variable values
- Updates the file
User:
I'm getting this error: "TypeError: Cannot read property 'name' of undefined"
Here's my code: [paste code]
AI Response:
- Identifies the issue
- Explains why it happens
- Suggests fixes
- Can update the code if requested
User:
Set up a new Python project structure with virtual environment, requirements.txt, and basic folders
What happens:
- Creates directory structure
- Generates requirements.txt
- Creates init.py files
- Provides setup instructions
User:
Create a basic React app structure with components, hooks, and utils folders
What happens:
my-app/
├── src/
│ ├── components/
│ │ └── App.jsx
│ ├── hooks/
│ │ └── useCustomHook.js
│ ├── utils/
│ │ └── helpers.js
│ └── index.js
├── public/
│ └── index.html
└── package.json
User:
Create a .eslintrc.json and .prettierrc for my JavaScript project
What happens:
- Creates ESLint configuration
- Creates Prettier configuration
- Both with sensible defaults
- Explains how to customize
User:
Create a JSON file with 10 sample user records including name, email, and age
What happens:
[
{
"id": 1,
"name": "Alice Johnson",
"email": "alice@example.com",
"age": 28
},
// ... 9 more records
]User:
Write an integration test that tests the entire user registration flow
What happens:
- AI creates test file
- Includes setup and teardown
- Tests complete workflow
- Adds assertions
User:
Run the tests in test_api.py and show me the results
What happens:
- AI executes
pytest test_api.py - Shows output
- Explains failures if any
- Suggests fixes
User:
Add docstrings to all functions in utils.py following Google style
What happens:
- AI reads the file
- Adds comprehensive docstrings
- Includes parameters, returns, examples
- Updates the file
User:
Document all the API endpoints in server.js in Markdown format
What happens:
- AI analyzes endpoints
- Creates API.md
- Includes request/response examples
- Lists all routes
User:
Create a comprehensive README for this project based on the files in the current directory
What happens:
- AI scans project structure
- Generates README with:
- Project description
- Installation instructions
- Usage examples
- API documentation
- Contributing guidelines
User:
Show me the current git status
What happens:
- AI runs
git_statustool - Shows modified, staged, untracked files
- Can suggest what to commit
User:
Based on the changes I've made, suggest a good commit message
What happens:
- AI reviews git status
- Suggests descriptive commit message
- Follows conventional commit format
User:
Read sales.csv, filter rows where amount > 1000, and save to high_value_sales.csv
What happens:
- AI writes Python script
- Processes the data
- Saves filtered results
- Shows summary statistics
User:
Convert users.json to users.csv with columns: id, name, email
What happens:
- AI reads JSON
- Converts to CSV format
- Saves to file
- Confirms conversion
User:
Analyze data.csv and show me:
- Total number of records
- Average of the 'value' column
- Top 5 highest values
What happens:
- AI processes the data
- Calculates statistics
- Presents results clearly
User:
Create a complete REST API with user authentication
AI Creates Plan:
## Phase 1: Setup
- [ ] Create project structure
- [ ] Initialize package.json
- [ ] Install dependencies
## Phase 2: Database
- [ ] Create user schema
- [ ] Set up database connection
- [ ] Create migration files
## Phase 3: Authentication
- [ ] Implement JWT auth
- [ ] Create login endpoint
- [ ] Create register endpoint
## Phase 4: User Routes
- [ ] Get user profile
- [ ] Update user
- [ ] Delete user
## Phase 5: Testing
- [ ] Write unit tests
- [ ] Write integration tests
- [ ] Test authentication flowThen:
Implement Phase 1 of the plan
User:
Review the code in app.py and suggest improvements for:
- Performance
- Readability
- Best practices
What happens:
- AI analyzes code
- Points out issues
- Suggests improvements
- Can apply changes if requested
User:
Convert the function in utils.js to Python
What happens:
- AI reads JavaScript code
- Converts to Python equivalent
- Maintains functionality
- Explains differences
User:
Read all .txt files in the docs/ folder and create a combined.txt with all their contents
What happens:
- AI lists directory
- Reads each file
- Combines content
- Saves to combined.txt
- User: "I have a bug in payment.py where discounts aren't being applied correctly"
- AI: Reads the file, finds the issue
- User: "Can you fix it?"
- AI: Fixes the bug
- User: "Add a test to prevent this in the future"
- AI: Creates test case
- User: "Add a rate limiting feature to the API"
- AI: Creates plan with steps
- User: "Implement step 1"
- AI: Creates middleware file
- User: "Continue with step 2"
- AI: Integrates middleware
- User: "Add tests"
- AI: Creates test cases
- User: "Show me the structure of this project"
- AI: Lists directory recursively
- User: "What does main.rs do?"
- AI: Reads and explains
- User: "How does it connect to the database?"
- AI: Finds and explains database code
"Make it better" "Add input validation and error messages to the login form"
"Fix the bug" "The calculate_total function returns NaN when the cart is empty. Fix this."
Instead of asking for everything at once, work step-by-step and refine as you go.
For complex tasks, ask for a plan first, then implement step by step.
Check the tool logs to see exactly what operations were performed.
| Task | Example Command |
|---|---|
| Create file | "Create a file named test.py" |
| Read file | "Show me the contents of config.json" |
| Modify file | "Update the API key in settings.py" |
| Delete file | "Remove the old_backup.sql file" |
| List files | "Show me all files in the src/ directory" |
| Run code | "Execute the script.py file" |
| Create plan | "Create a plan to build a blog system" |
| Check git | "Show git status" |
| Get stats | "/stats" |
| Quit | "/quit" or Ctrl+C |
For more examples and inspiration, experiment with your own use cases! The AI is designed to help with a wide variety of development tasks.