GithubHelp home page GithubHelp logo

hanoglu / termic Goto Github PK

View Code? Open in Web Editor NEW
274.0 3.0 8.0 90 KB

GCC powered interactive C/C++ REPL terminal created with BASH

License: GNU General Public License v3.0

Shell 100.00%
shell gcc bash-script interactive-c interactive-shell repl

termic's Introduction

TermiC: Terminal C

Interactive C/C++ REPL shell created with BASH.

How to Use

A simple function in TermiC:

[user@FEDORA ~]$ termic
TermiC 1.3.0V
Language: c
Compiler: gcc
Type 'help' for additional information
>> double divide(double a, double b) {
   ...if(b==0) {
   ......return 0;
   ......}
   ...return a/b;
   ...}
>> printf("Division 25/2 is equal %f", divide(25,2))
Division 25/2 is equal 12.500000
>> 

Implementing classes in TermiC++:

[user@FEDORA ~]$ termic++
TermiC 1.3.0V
Language: c++
Compiler: g++ -fpermissive
Type 'help' for additional information
>> class Student {
   ...public:
   ...Student(int age) {
   ......this->age = age;
   ......}
   ...int getAge() {
   ......return age;
   ......}
   ...private:
   ...int age;
   ...}
>> Student a(15)
>> cout << "Age of student 'a' " << a.getAge()
Age of student 'a' 15
>> 

Using vectors in TermiC++:

[user@FEDORA ~]$ termic++
TermiC 1.3.0V
Language: c++
Compiler: g++ -fpermissive
Type 'help' for additional information
>> #include <vector>
>> vector<int> a
>> a.push_back(10)
>> a.push_back(11)
>> a.push_back(12)
>> short counter = 0
>> for(auto v:a) {
   ...cout << ++counter << ". element of a is " << v << endl;
   ...}
1. element of a is 10
2. element of a is 11
3. element of a is 12
>> 

Note: stdio.h, stdlib.h and iostream(in TermiC++) are included automatically. Prompt will be inside scope of int main() function but all declared functions/namespaces/classes/structs will be declared before int main() automatically.

How it Works

All inputs given to TermiC are append to text file in /tmp directory. Then TermiC compiles that file and runs it. It simply takes the last line back if an output detected as all outputs should be seen once. TermiC nearly fully supports C and C++ as it basically use GCC and G++ compilers. All curly braces starts an inline prompt so nested functions, if/else statements, while/for loops, classes etc. can be used efficiently. I don't know if there is such a concept, but I hope it will be useful.

Prompt Commands

Commands Explanation
help Shows the help menu
abort Aborts inline prompt mode which are entered by curly bracket
show Prints last successfully compiled source file
showtmp Prints last compiled source file with deleted edits
save Saves source file to working directory
savebin Saves binary file to working directory
clear Deletes all declared functions,classes etc. and resets shell
exit Deletes created temp files and exits program

How to Install

TermiC uses following packages:

gcc
g++

To install dependencies:

apt install gcc g++ # Debian based distros
dnf install gcc gcc-c++ # Fedora based distros

To run TermiC:

wget "https://raw.githubusercontent.com/hanoglu/TermiC/main/TermiC.sh"
chmod +x TermiC.sh
bash TermiC.sh

To install TermiC system wide:

wget "https://raw.githubusercontent.com/hanoglu/TermiC/main/TermiC.sh"
sudo cp TermiC.sh /bin/termic
sudo ln -sf /usr/bin/termic /usr/bin/termic++
sudo chmod +x /bin/termic
rm -f TermiC.sh

Note: DEB and RPM files in releases page can be used to install TermiC in Debian/Fedora based systems. Also COPR repository can be used to install TermiC in Fedora based distros.

Install with COPR:

sudo dnf copr enable hanoglu/termic
sudo dnf install termic

To start TermiC:

termic # For C shell
termic++ # For C++ shell
termic tcc # For C shell using the tcc compiler

To remove TermiC system wide:

sudo rm -f /bin/termic
sudo rm -f /bin/termic++

termic's People

Contributors

hanoglu avatar maxgyver83 avatar virtuosonic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

termic's Issues

Similar project

Hey ๐Ÿ‘‹,
Thanks for the tool, i was interested so checked it out.
Actually, reading the usage i thought of another command cling, that i use.

The main difference being cling from scratch uses LLVM, and termiC uses GCC.
The main cons of cling for me was it's large size, termiC wins here.

Just wanted to mention it to you, it might help proceed with new features :)

Could not work with classes

I was testing with simple functions, which worked then, but when I tried to implement classes with it, it did not work. I installed dependencies.

issue

Integrate the ReadLine library for better development experience

Hello, and thanks a lot for this amazing project. i really love it.

Just one suggestion. there is a library called: ReadLine that will add a lot of cool features to console applications. for example, you can provide auto-suggestion, auto-completion, etc.. with it.

Clink extensively use it and to be honest, clink+cmd is an amazing experience for me:
https://chrisant996.github.io/clink/

I hope TermiC also integrates it into itself.

Some code running but not saved

if I type the following code it runs Ok

>> #include <iterator>
>> #include <algorithm>
>> #include <math.h>
>> #include <vector>
>> vector<double> v;
>> v.push_back(M_PI);
>> v.push_back(1.0);
>> std::copy(v.begin(),v.end(),ostream_iterator<double>(cout," "));
3.14159 1 

but when typing the show command the copy call doesn't show

>> show
#include <vector>
#include <math.h>
#include <algorithm>
#include <iterator>
#include "stdio.h"
#include "stdlib.h"
#include <iostream>
using namespace std;
int main() {
vector<double> v;
v.push_back(M_PI);
v.push_back(1.0);

if I add more code it works but doesn't add the copy call

>> int number = 1234567890
>> show
#include <vector>
#include <math.h>
#include <algorithm>
#include <iterator>
#include "stdio.h"
#include "stdlib.h"
#include <iostream>
using namespace std;
int main() {
vector<double> v;
v.push_back(M_PI);
v.push_back(1.0);
int number = 1234567890;

same case here with the for loop, but the initialization after gets saved

>> #include <map>
>> map<int,string> m;
>> m[42] = "the ultimate answer";
>> m[0] = "you are worth nothing";
>> for (auto p : m) {
   ...cout << p.first << " " << p.second << endl;
   ...}
0 you are worth nothing
42 the ultimate answer
>> string othervar = "other va"
>> show
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <iterator>
#include "stdio.h"
#include "stdlib.h"
#include <iostream>
using namespace std;
int main() {
vector<double> v;
v.push_back(M_PI);
v.push_back(1.0);
int number = 1234567890;
map<int,string> m;
m[42] = "the ultimate answer";
m[0] = "you are worth nothing";
string othervar = "other va";

TermiC does not exit after EOF, but exits after receiving a SIGINT

After receiving an EOF character (Ctrl+D) on an empty line, TermiC does not exit, and opens a new line.

Instead, sending a SIGINT (Ctrl+C) would quit TermiC in the same way I expected an EOF to do so. But SIGINT should not stop a REPL.

Ideally, I think it should behave like other REPLs such as bash, where the program would end after an EOF, which is much more intuitive (since we are using bash already!).

Great job on this nifty piece of shell script btw! I use it a lot for quick things like getting the sizeof of a non-standard type in GCC, and it's neaten up my workflow a lot by removing the need for temporary source files everywhere on my desktop :P

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.