Skip to content

Commit

Permalink
prepare for release
Browse files Browse the repository at this point in the history
  • Loading branch information
RelativisticMechanic committed Jul 24, 2023
1 parent e512835 commit 677b1d6
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The terminal supports a subset of VT220, and uses SDL-GPU for rendering. For the

The terminal reads the "default" file in its directory which should just contain the path to a JSON file. An example is given in default and config/ located in src/resources.

A release is planned in the near future.
The current version is 0.2.0, it is still in active development and may not replace your terminal application.

## Features

Expand Down
113 changes: 113 additions & 0 deletions src/ArgumentParser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#include <iostream>
#include "ArgumentParser.h"

inline bool expectArg(int current, int argc, std::string error)
{
if (!(current < argc))
{
std::cerr << "[ERROR] expected argumnet for: " << error << std::endl;
exit(-1);
}
}

inline void unrecognisedArg(std::string arg)
{
std::cerr << "[ERROR] unrecognised argument: " << arg << std::endl;
exit(-1);
}

inline void invalidArg(std::string arg, std::string value)
{
std::cerr << "[ERROR] Invalid argument to '" << arg << "': " << value << std::endl;
exit(-1);
}

void ArgumentParser::Parse(int argc, char** argv)
{
for (int i = 1; i < argc; i++)
{
std::string current_arg = std::string(argv[i]);
if (this->parser_state == ARGUMENT_ATTR)
{
this->argmap[this->processing_arg] = current_arg;
this->parser_state = ARGUMENT_NORMAL;
}
else
{
if (current_arg[0] != '-')
{
/* If this is the first argument and doesnt begin with a dash, just store it */
if (this->parser_state == ARGUMENT_LIST_BEGIN)
{
this->argmap["first_argument"] = current_arg;
this->argmap[this->first_arg] = current_arg;
}
else
{
unrecognisedArg(current_arg);
}
}
else
{
/* Remove the '-' */
current_arg.erase(0, 1);
if (std::find(this->expected_args.begin(), this->expected_args.end(), current_arg) != this->expected_args.end())
{
this->parser_state = ARGUMENT_ATTR;
this->processing_arg = current_arg;
}
else
{
unrecognisedArg(current_arg);
}
}
}
}
}

void ArgumentParser::AddArgument(std::string arg, bool first_arg)
{
this->expected_args.push_back(arg);
if (first_arg)
{
this->first_arg = arg;
}
}

void ArgumentParser::GetArgument(std::string arg, std::string& result)
{
if (this->argmap.find(arg) != this->argmap.end())
{
result = this->argmap[arg];
}
}

void ArgumentParser::GetArgument(std::string arg, int& result)
{
if (this->argmap.find(arg) != this->argmap.end())
{
try
{
result = std::stoi(this->argmap[arg]);
}
catch (...)
{
invalidArg(arg, this->argmap[arg]);
}
}
}

void ArgumentParser::GetArgument(std::string arg, float& result)
{
if (this->argmap.find(arg) != this->argmap.end())
{
try
{
result = std::stof(this->argmap[arg]);
}
catch (...)
{
invalidArg(arg, this->argmap[arg]);
}
}
}
35 changes: 35 additions & 0 deletions src/ArgumentParser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Nicely written class for parsing arguments. Heh, just kidding, I wrote this for some C++ practice.
*/

#ifndef ARGUMENT_PARSER_H
#define ARGUMENT_PARSER_H

#include <string>

#include "CRTermConfig.h"

typedef enum
{
ARGUMENT_LIST_BEGIN,
ARGUMENT_NORMAL,
ARGUMENT_ATTR
} ARGUMENT_PARSER_STATE;

class ArgumentParser
{
public:
ARGUMENT_PARSER_STATE parser_state = ARGUMENT_LIST_BEGIN;
std::unordered_map<std::string, std::string> argmap;
std::vector<std::string> expected_args;
std::string first_arg;
std::string processing_arg;
ArgumentParser(void) { };
void Parse(int argc, char** argv);
void AddArgument(std::string argument, bool first_arg = false);
void GetArgument(std::string, std::string&);
void GetArgument(std::string, float&);
void GetArgument(std::string, int&);
};

#endif
18 changes: 17 additions & 1 deletion src/CRTerm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "imgui_impl_sdl2.h"
#include "imgui_impl_opengl3.h"

#define SDL_MAIN_HANDLED
#include "SDL_gpu.h"
#include "CustomTitleBar.h"
#include "Shaders.h"
Expand All @@ -18,16 +19,31 @@
#include "ConfigEditor.h"
#include "ConfigSelector.h"
#include "ContextMenu.h"
#include "ArgumentParser.h"

/* SDLmain requires this. It seems to define its own main. */
#undef main

void menuCallBack(int, void*);

int main()
int main(int argc, char* argv[])
{
/* Read the path of the configuration JSON from "default" and then load it */
CRTermConfiguration* cfg = new CRTermConfiguration(GetDefaultConfigJSON());

/* Parse arguments */
ArgumentParser arg_parse;
arg_parse.AddArgument("fs");
arg_parse.AddArgument("cw");
arg_parse.AddArgument("ch");
arg_parse.AddArgument("cmd", true);

arg_parse.Parse(argc, argv);

arg_parse.GetArgument("cw", cfg->console_width);
arg_parse.GetArgument("ch", cfg->console_height);
arg_parse.GetArgument("fs", cfg->font_scale);
arg_parse.GetArgument("cmd", cfg->shell_command);

/* Calculate the required screen resolution from the configuration */
int resolution_x = (int)(cfg->font_width * cfg->font_scale * cfg->console_width) + 2 * SIDES_WIDTH;
Expand Down
2 changes: 1 addition & 1 deletion src/CRTerm.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef CRTERM_H
#define CRTERM_H

#define CRTERM_VERSION_STRING "CRTerm 0.1.0"
#define CRTERM_VERSION_STRING "CRTerm 0.2.0"
#define CRTERM_CREDIT_STRING "(C) Siddharth Gautam, 2023\nThis software comes with NO WARRANTY.\n"

#endif
Binary file modified src/CRTerm.rc
Binary file not shown.
11 changes: 7 additions & 4 deletions src/CRTerm.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,17 @@
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(ProjectDir)lib\SDL2;$(ProjectDir)lib\SDL2_gpu;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>SDL2main.lib;SDL2.lib;SDL2_gpu.lib;winmm.lib;Dwmapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>SDL2.lib;SDL2main.lib;SDL2_gpu.lib;winmm.lib;Dwmapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="ArgumentParser.cpp" />
<ClCompile Include="ConfigEditor.cpp" />
<ClCompile Include="ConfigSelector.cpp" />
<ClCompile Include="ContextMenu.cpp" />
Expand All @@ -160,6 +162,7 @@
<ClCompile Include="Win32ClipBoard.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="ArgumentParser.h" />
<ClInclude Include="CRTerm.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="UITheme.h" />
Expand Down Expand Up @@ -280,8 +283,8 @@
<ResourceCompile Include="CRTerm.rc" />
</ItemGroup>
<ItemGroup>
<Image Include="..\images\crt_logo.png" />
<Image Include="resources\logo.png" />
<Image Include="crterm.ico" />
<Image Include="icon.png" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
10 changes: 8 additions & 2 deletions src/CRTerm.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
<ClCompile Include="CustomTitlebar.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ArgumentParser.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Shaders.h">
Expand Down Expand Up @@ -437,17 +440,20 @@
<ClInclude Include="CRTerm.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="ArgumentParser.h">
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="CRTerm.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<Image Include="resources\logo.png">
<Image Include="icon.png">
<Filter>Resource Files</Filter>
</Image>
<Image Include="..\images\crt_logo.png">
<Image Include="crterm.ico">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
Expand Down
Binary file added src/crterm.ico
Binary file not shown.
Binary file added src/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// Microsoft Visual C++ generated include file.
// Used by CRTerm.rc
//
#define IDI_ICON1 104

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 103
#define _APS_NEXT_RESOURCE_VALUE 105
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
Expand Down
2 changes: 1 addition & 1 deletion src/resources/config/default_cmd.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"crt_shader": "shaders/crt",
"bell": "bell.wav",
"crt_warp": 0.0,
"shell_command": "cmd.exe %USERPROFILE%",
"shell_command": "cmd /K \"cd %userprofile%\"",
"blink_interval": 300,
"default_fg": 2,
"default_bg": 2,
Expand Down

0 comments on commit 677b1d6

Please sign in to comment.