Skip to content

Commit 2f54365

Browse files
committed
chore: small changes
1 parent 688cd01 commit 2f54365

File tree

6 files changed

+68
-74
lines changed

6 files changed

+68
-74
lines changed

.github/workflows/build-test.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Build test
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Build
17+
run: cmake ${{ github.workspace }}
18+
19+
- name: Compile
20+
run: make -j$(nproc)
21+
22+
- name: Run
23+
run: ./calcplusplus

.github/workflows/tests.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.idea/
2+
.cache/
23

34
build/
45
out/

CMakeLists.txt

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,41 @@
1-
cmake_minimum_required(VERSION 3.28)
1+
cmake_minimum_required(VERSION 3.25)
22

3-
set(EXEC_NAME "calcplusplus")
4-
project(calcplusplus VERSION 0.1.0)
3+
project(calcplusplus VERSION 0.1.0 LANGUAGES CXX)
4+
5+
set(CMAKE_CXX_STANDARD 20)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
set(CMAKE_CXX_EXTENSIONS OFF)
8+
9+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
510

611
if(NOT DEFINED CMAKE_BUILD_TYPE)
712
set(CMAKE_BUILD_TYPE "Debug")
813
endif()
914

10-
set(ENABLE_SAMPLES OFF)
11-
set(BUILD_TESTING OFF)
12-
set(ENABLE_OPENMP OFF)
15+
add_compile_options(
16+
-Wall -Wextra -Wpedantic
17+
)
18+
19+
file(GLOB HEADERS "include/*.h" "include/*.hpp" "include/*.hh" "include/*.hxx")
20+
message(STATUS "Found headers: ${HEADERS}")
21+
file(GLOB SOURCES "src/*.c" "src/*.cpp" "src/*.cc" "src/*.cxx")
22+
message(STATUS "Found sources: ${SOURCES}")
23+
24+
add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES})
25+
target_include_directories(${PROJECT_NAME} PRIVATE include)
1326

1427
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
15-
set(FTXUI_DEV_WARNINGS ON)
16-
17-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
28+
target_compile_definitions(${PROJECT_NAME} PRIVATE DEBUG_MODE=1)
29+
target_compile_options(${PROJECT_NAME} PRIVATE -Og -g3 -DDEBUG)
30+
target_link_options(${PROJECT_NAME} PRIVATE -fsanitize=address)
31+
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
32+
target_compile_options(${PROJECT_NAME} PRIVATE -O3 -march=native -flto -DNDEBUG)
33+
target_link_options(${PROJECT_NAME} PRIVATE -flto)
1834
endif()
1935

36+
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/include PREFIX "Header Files" FILES ${HEADERS})
37+
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src PREFIX "Source Files" FILES ${SOURCES})
38+
2039
include(FetchContent)
2140

2241
FetchContent_Declare(ftxui
@@ -39,30 +58,7 @@ if(NOT muparser_POPULATED)
3958
add_subdirectory(${muparser_SOURCE_DIR} ${muparser_BINARY_DIR} EXCLUDE_FROM_ALL)
4059
endif()
4160

42-
file(GLOB HEADERS
43-
"include/*.h"
44-
"include/*.hh"
45-
"include/*.hpp"
46-
"include/*.hxx"
47-
)
48-
49-
file(GLOB SRC
50-
"src/*.c"
51-
"src/*.cc"
52-
"src/*.cpp"
53-
"src/*.cxx"
54-
)
55-
56-
include_directories(include)
57-
58-
add_executable(${EXEC_NAME} ${SRC} ${HEADERS})
59-
target_include_directories(${EXEC_NAME} PRIVATE ${HEADERS})
60-
61-
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
62-
target_link_options(${EXEC_NAME} PRIVATE -fsanitize=address)
63-
endif()
64-
65-
target_link_libraries(${EXEC_NAME}
61+
target_link_libraries(${PROJECT_NAME}
6662
PRIVATE ftxui::screen
6763
PRIVATE ftxui::dom
6864
PRIVATE ftxui::component

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
<h1 align="center">calcplusplus</h1>
22
<h2 align="center">TUI calculator written in C++ using FTXUI</h2>
33

4-
<div align="center">
4+
<p align="center">
55
<img alt="Stargazers" src="https://img.shields.io/github/stars/budchirp/calcplusplus?style=for-the-badge&colorA=0b1221&colorB=ff8e8e" />
66
<img alt="Last commit" src="https://img.shields.io/github/last-commit/budchirp/calcplusplus?style=for-the-badge&colorA=0b1221&colorB=BDB0E4" />
77
<img alt="Issues" src="https://img.shields.io/github/issues/budchirp/calcplusplus?style=for-the-badge&colorA=0b1221&colorB=FBC19D" />
8-
</div>
8+
</p>
99

1010

11-
## 💾 Installation
11+
## 💾 Getting started
1212

1313
### Requirements
1414

15-
1. C compiler
15+
1. C++ compiler
1616
2. CMake & Make
1717

18-
### How to install?
18+
### How to start?
1919

2020
1. Clone the repo
2121

@@ -26,8 +26,8 @@ git clone https://github.com/budchirp/calcplusplus && cd calcplusplus
2626
2. Compile the code
2727

2828
```sh
29-
mkdir -p build && cd build
30-
cmake ../ && make -j$(nproc)
29+
mkdir build && cd build
30+
cmake .. && make -j$(nproc)
3131
```
3232

3333
> NOTE: If you're using fish, remove the `$` sign.
@@ -36,4 +36,4 @@ cmake ../ && make -j$(nproc)
3636

3737
```sh
3838
./calcplusplus
39-
```
39+
```

src/main.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <csignal>
21
#include <string>
32

43
#include "ftxui/component/component.hpp"
@@ -12,7 +11,7 @@ using namespace std;
1211
using namespace ftxui;
1312
using namespace mu;
1413

15-
string calculate(const string& expression) {
14+
string calculate(const string &expression) {
1615
try {
1716
if (!expression.empty()) {
1817
Parser parser;
@@ -30,7 +29,7 @@ string calculate(const string& expression) {
3029
} else {
3130
return "";
3231
}
33-
} catch (Parser::exception_type& e) {
32+
} catch (Parser::exception_type &e) {
3433
return e.GetMsg();
3534
}
3635
}
@@ -56,7 +55,8 @@ int main() {
5655
calculated = "";
5756
});
5857
Component removeButton = Button(" R ", [&] {
59-
if (!expression.empty()) expression.pop_back();
58+
if (!expression.empty())
59+
expression.pop_back();
6060
});
6161
Component plusButton = Button(" + ", [&] { expression.append("+"); });
6262
Component minusButton = Button(" - ", [&] { expression.append("-"); });
@@ -96,9 +96,9 @@ int main() {
9696
hbox(text(" "), bold(text("calc++")), text(" "),
9797
filler() | borderEmpty, quitButton->Render()),
9898
vbox(
99-
vbox(hbox(
100-
hbox(expressionsInput->Render()) | flex | border,
101-
hbox(text(" "), text(calculated), text(" ")) | border)),
99+
vbox(hbox(hbox(expressionsInput->Render()) | flex | border,
100+
hbox(text(" "), text(calculated), text(" ")) |
101+
border)),
102102
vbox(hbox(clearButton->Render(), removeButton->Render(),
103103
emptyButton2->Render(), dividedByButton->Render()),
104104
hbox(button7->Render(), button8->Render(),

0 commit comments

Comments
 (0)