Skip to content

Commit

Permalink
Improve interface handling.
Browse files Browse the repository at this point in the history
Increments-minor-version-of: ttyr-api
Increments-minor-version-of: ttyr-tty
Increments-patch-version-of: other
  • Loading branch information
dajofrey committed Jan 26, 2024
1 parent 83cb8fb commit 5f28a3b
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 52 deletions.
45 changes: 40 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

Terminal Emulator Written In C99.

![tiling](./build/data/image/screenshot.png)
![screenshot](./build/data/image/screenshot.png)

What makes TTýr special?
What makes TTýr different?

- Minimalistic Design
- Hybrid Tabing/Tiling
Expand All @@ -13,16 +13,51 @@ What makes TTýr special?

## Contents

- [Compatibilities](#Compatibilities)
- [Dependencies](#Dependencies)
- [Build](#Build)
- [API](#API)

## Compatibilities

| Operating System | Compatibility |
| --- | --- |
| Linux | Yes |
| MacOS | No |
| Windows | No |

| Window System | Compatibility |
| --- | --- |
| X11 | Yes |
| Wayland | No |

| Graphics Driver | Compatibility |
| --- | --- |
| OpenGL | Yes |
| Vulkan | No |
| DirectX | No |

## Dependencies

The following dependencies **must be present** on the system.

* [Git](https://git-scm.com)
For submodules.
* [Make](https://www.gnu.org/software/make)
For building.

The following dependencies **are automatically compiled** during the build process.

* [Netzhaut](https://github.com/dajofrey/netzhaut)
TTýr is companion project to [Netzhaut](https://github.com/dajofrey/netzhaut), from which it requires nhapi, nhcore, nhencoding, nhwsi and nhgfx modules.
* [st](https://st.suckless.org/)
For shell functionality, TTýr uses parts of the great [st](https://st.suckless.org/).

## Build

### Linux

```bash
git clone https://github.com/dajofrey/TTyr
cd TTyr && git submodule update --init --recursive
make -f build/automation/Makefile all
```
## API
TODO
2 changes: 1 addition & 1 deletion src/bin/ttyr/Main.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ int main(int argc, char **argv_pp)

nh_api_registerConfig("/etc/ttyr.conf", 14);

TTY_p = ttyr_api_openTTY(NULL);
TTY_p = ttyr_api_openTTY(NULL, NULL);
if (!TTY_p) {return 1;}

ttyr_terminal_Terminal *Terminal_p = ttyr_api_openTerminal(NULL, TTY_p);
Expand Down
6 changes: 3 additions & 3 deletions src/lib/ttyr-api/ttyr-tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// TYPEDEFS ========================================================================================

typedef ttyr_tty_TTY *(*ttyr_tty_openTTY_f)(
char *config_p
char *config_p, ttyr_tty_Interface *Interface_p
);

typedef TTYR_TTY_RESULT (*ttyr_tty_closeTTY_f)(
Expand Down Expand Up @@ -49,11 +49,11 @@ static void ttyr_api_initialize() {
}

ttyr_tty_TTY *ttyr_api_openTTY(
NH_BYTE *config_p)
NH_BYTE *config_p, ttyr_tty_Interface *Interface_p)
{
ttyr_api_initialize();
ttyr_tty_openTTY_f openTTY_f = !NH_LOADER_P ? NULL : NH_LOADER_P->loadExternalSymbol_f(name_p, "ttyr_tty_openTTY");
return openTTY_f ? openTTY_f(config_p) : NULL;
return openTTY_f ? openTTY_f(config_p, Interface_p) : NULL;
}

TTYR_TTY_RESULT ttyr_api_closeTTY(
Expand Down
20 changes: 11 additions & 9 deletions src/lib/ttyr-api/ttyr-tty.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

typedef struct ttyr_tty_TTY ttyr_tty_TTY;
typedef struct ttyr_tty_Program ttyr_tty_Program;
typedef struct ttyr_tty_ProgramPrototype ttyr_tty_ProgramPrototype;
typedef struct ttyr_tty_Interface ttyr_tty_Interface;
typedef struct ttyr_tty_Glyph ttyr_tty_Glyph;

typedef void *(*ttyr_tty_init_f)(void *arg_p);
Expand All @@ -75,7 +75,7 @@
typedef TTYR_TTY_RESULT (*ttyr_tty_update_f)(ttyr_tty_Program *Program_p);
typedef TTYR_TTY_RESULT (*ttyr_tty_handleCommand_f)(ttyr_tty_Program *Program_p, nh_List *Arguments_p);
typedef void (*ttyr_tty_destroy_f)(void *p);
typedef void (*ttyr_tty_destroyPrototype_f)(ttyr_tty_ProgramPrototype *Prototype_p);
typedef void (*ttyr_tty_destroyPrototype_f)(ttyr_tty_Interface *Prototype_p);

// STRUCTS =========================================================================================

Expand Down Expand Up @@ -110,7 +110,7 @@
bool *update_p;
} ttyr_tty_Row;

typedef struct ttyr_tty_ProgramCallbacks {
typedef struct ttyr_tty_InterfaceCallbacks {
ttyr_tty_init_f init_f;
ttyr_tty_draw_f draw_f;
ttyr_tty_drawTopbar_f drawTopbar_f;
Expand All @@ -120,18 +120,18 @@
ttyr_tty_handleCommand_f handleCommand_f;
ttyr_tty_destroy_f destroy_f;
ttyr_tty_destroyPrototype_f destroyPrototype_f;
} ttyr_tty_ProgramCallbacks;
} ttyr_tty_InterfaceCallbacks;

typedef struct ttyr_tty_ProgramPrototype {
typedef struct ttyr_tty_Interface {
nh_encoding_UTF32String Name;
nh_encoding_UTF32String *CommandNames_p;
int commands;
ttyr_tty_ProgramCallbacks Callbacks;
ttyr_tty_InterfaceCallbacks Callbacks;
void *initArg_p;
} ttyr_tty_ProgramPrototype;
} ttyr_tty_Interface;

typedef struct ttyr_tty_Program {
ttyr_tty_ProgramPrototype *Prototype_p;
ttyr_tty_Interface *Prototype_p;
void *handle_p;
bool refresh;
bool close;
Expand All @@ -148,10 +148,12 @@
* the user probably closed the TTY or there was an error. You can force-close the TTY with
* @ref ttyr_tty_closeTTY.
*
* @param Interface_p Pointer to an interface or NULL. If NULL, shell interface will be used.
*
* @return Pointer to a new TTY handle. NULL on failure.
*/
ttyr_tty_TTY *ttyr_api_openTTY(
char *config_p
char *config_p, ttyr_tty_Interface *Interface_p
);

/**
Expand Down
8 changes: 4 additions & 4 deletions src/lib/ttyr-tty/Editor/Editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ typedef enum TTYR_TTY_EDITOR_COMMAND_E {
} TTYR_TTY_EDITOR_COMMAND_E;

static void ttyr_tty_destroyEditorPrototype(
ttyr_tty_ProgramPrototype *Prototype_p)
ttyr_tty_Interface *Prototype_p)
{
nh_encoding_freeUTF32(&Prototype_p->Name);
nh_encoding_freeUTF32(&Prototype_p->CommandNames_p[0]);
Expand All @@ -462,12 +462,12 @@ static void ttyr_tty_destroyEditorPrototype(
nh_core_free(Prototype_p);
}

ttyr_tty_ProgramPrototype *ttyr_tty_createEditorPrototype()
ttyr_tty_Interface *ttyr_tty_createEditorPrototype()
{
ttyr_tty_ProgramPrototype *Prototype_p = nh_core_allocate(sizeof(ttyr_tty_ProgramPrototype));
ttyr_tty_Interface *Prototype_p = nh_core_allocate(sizeof(ttyr_tty_Interface));
TTYR_CHECK_MEM_2(NULL, Prototype_p)

memset(Prototype_p, 0, sizeof(ttyr_tty_ProgramPrototype));
memset(Prototype_p, 0, sizeof(ttyr_tty_Interface));

Prototype_p->Callbacks.init_f = ttyr_tty_initEditor;
Prototype_p->Callbacks.draw_f = ttyr_tty_drawEditor;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ttyr-tty/Editor/Editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
* @{
*/

ttyr_tty_ProgramPrototype *ttyr_tty_createEditorPrototype(
ttyr_tty_Interface *ttyr_tty_createEditorPrototype(
);

/** @} */
Expand Down
8 changes: 4 additions & 4 deletions src/lib/ttyr-tty/Shell/Shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ static void ttyr_tty_destroyShell(
// PROTOTYPE =======================================================================================

static void ttyr_tty_destroyShellPrototype(
ttyr_tty_ProgramPrototype *Prototype_p)
ttyr_tty_Interface *Prototype_p)
{
nh_encoding_freeUTF32(&Prototype_p->Name);

Expand All @@ -1149,12 +1149,12 @@ static void ttyr_tty_destroyShellPrototype(
nh_core_free(Prototype_p);
}

ttyr_tty_ProgramPrototype *ttyr_tty_createShellPrototype()
ttyr_tty_Interface *ttyr_tty_createShellInterface()
{
ttyr_tty_ProgramPrototype *Prototype_p = nh_core_allocate(sizeof(ttyr_tty_ProgramPrototype));
ttyr_tty_Interface *Prototype_p = nh_core_allocate(sizeof(ttyr_tty_Interface));
TTYR_CHECK_MEM_2(NULL, Prototype_p)

memset(Prototype_p, 0, sizeof(ttyr_tty_ProgramPrototype));
memset(Prototype_p, 0, sizeof(ttyr_tty_Interface));

Prototype_p->Callbacks.init_f = ttyr_tty_initShell;
Prototype_p->Callbacks.draw_f = ttyr_tty_drawShellRow;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ttyr-tty/Shell/Shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @{
*/

ttyr_tty_ProgramPrototype *ttyr_tty_createShellPrototype(
ttyr_tty_Interface *ttyr_tty_createShellInterface(
);

/** @} */
Expand Down
6 changes: 3 additions & 3 deletions src/lib/ttyr-tty/TTY/ContextMenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,12 @@ ttyr_tty_ContextMenu *ttyr_tty_createMouseMenu(
nh_encoding_appendUTF32(&Menu, apps_p, sizeof(apps_p)/sizeof(apps_p[0]));
int width = 0;
for (int i = 0; i < TTY_p->Prototypes.size; ++i) {
if (((ttyr_tty_ProgramPrototype*)TTY_p->Prototypes.pp[i])->Name.length > width) {
width = ((ttyr_tty_ProgramPrototype*)TTY_p->Prototypes.pp[i])->Name.length;
if (((ttyr_tty_Interface*)TTY_p->Prototypes.pp[i])->Name.length > width) {
width = ((ttyr_tty_Interface*)TTY_p->Prototypes.pp[i])->Name.length;
}
}
for (int i = 0; i < TTY_p->Prototypes.size; ++i) {
ttyr_tty_ProgramPrototype *Prototype_p = TTY_p->Prototypes.pp[i];
ttyr_tty_Interface *Prototype_p = TTY_p->Prototypes.pp[i];
nh_encoding_appendUTF32(&Menu, Prototype_p->Name.p, Prototype_p->Name.length);
for (int j = width - Prototype_p->Name.length; j > 0; --j) {
nh_encoding_appendUTF32Codepoint(&Menu, ' ');
Expand Down
6 changes: 3 additions & 3 deletions src/lib/ttyr-tty/TTY/Micro.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TTYR_TTY_RESULT ttyr_tty_getMicroTiles(
// MICRO TABS ======================================================================================

static ttyr_tty_MicroTab *ttyr_tty_createMicroTab(
ttyr_tty_ProgramPrototype *Prototype_p, NH_BOOL once)
ttyr_tty_Interface *Prototype_p, NH_BOOL once)
{
ttyr_tty_MicroTab *Tab_p = nh_core_allocate(sizeof(ttyr_tty_MicroTab));
TTYR_CHECK_MEM_2(NULL, Tab_p)
Expand All @@ -86,7 +86,7 @@ nh_List *ttyr_tty_createMicroTabs(
*Tabs_p = nh_core_initList(8); // Don't change size to TTY_p->Prototypes.size, it might not be initialized.

for (int i = 0; i < TTY_p->Prototypes.size; ++i) {
ttyr_tty_ProgramPrototype *Prototype_p = TTY_p->Prototypes.pp[i];
ttyr_tty_Interface *Prototype_p = TTY_p->Prototypes.pp[i];
ttyr_tty_MicroTab *Tab_p = ttyr_tty_createMicroTab(Prototype_p, NH_FALSE);
TTYR_CHECK_NULL_2(NULL, Tab_p)
nh_core_appendToList(Tabs_p, Tab_p);
Expand All @@ -103,7 +103,7 @@ static void ttyr_tty_freeMicroTab(
}

TTYR_TTY_RESULT ttyr_tty_appendMicroTab(
ttyr_tty_MicroWindow *Window_p, ttyr_tty_ProgramPrototype *Prototype_p, NH_BOOL once)
ttyr_tty_MicroWindow *Window_p, ttyr_tty_Interface *Prototype_p, NH_BOOL once)
{
ttyr_tty_MicroTab *Tab_p = ttyr_tty_createMicroTab(Prototype_p, once);
TTYR_CHECK_NULL(Tab_p)
Expand Down
4 changes: 2 additions & 2 deletions src/lib/ttyr-tty/TTY/Micro.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
} ttyr_tty_MicroTile;

typedef struct ttyr_tty_MicroTab {
ttyr_tty_ProgramPrototype *Prototype_p; /**<Type of programs spawned by this micro tab.*/
ttyr_tty_Interface *Prototype_p; /**<Type of programs spawned by this micro tab.*/
ttyr_tty_Tile *RootTile_p; /**<Root tile.*/
ttyr_tty_Tile *Tile_p; /**<Current focused tile.*/
ttyr_tty_Tile *LastFocus_p;
Expand Down Expand Up @@ -57,7 +57,7 @@
);

TTYR_TTY_RESULT ttyr_tty_appendMicroTab(
ttyr_tty_MicroWindow *Window_p, ttyr_tty_ProgramPrototype *Prototype_p, NH_BOOL once
ttyr_tty_MicroWindow *Window_p, ttyr_tty_Interface *Prototype_p, NH_BOOL once
);

TTYR_TTY_RESULT ttyr_tty_getMicroTiles(
Expand Down
8 changes: 4 additions & 4 deletions src/lib/ttyr-tty/TTY/Program.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
// PROGRAM INSTANCE ================================================================================

ttyr_tty_Program *ttyr_tty_createProgramInstance(
ttyr_tty_ProgramPrototype *Prototype_p, bool once)
ttyr_tty_Interface *Prototype_p, bool once)
{
ttyr_tty_Program *Program_p = nh_core_allocate(sizeof(ttyr_tty_Program));
TTYR_CHECK_MEM_2(NULL, Program_p)
Expand Down Expand Up @@ -62,7 +62,7 @@ TTYR_TTY_RESULT ttyr_tty_destroyProgramInstance(
// INTERFACE =======================================================================================

TTYR_TTY_RESULT ttyr_tty_addProgram(
ttyr_tty_TTY *TTY_p, ttyr_tty_ProgramPrototype *Prototype_p, bool once)
ttyr_tty_TTY *TTY_p, ttyr_tty_Interface *Prototype_p, bool once)
{
// if (once) {
// ttyr_tty_MacroTile *Tile_p = TTY_p->Window_p->Tile_p;
Expand Down Expand Up @@ -93,7 +93,7 @@ TTYR_TTY_RESULT ttyr_tty_addProgram(

// Check if there already exists a program with this name.
for (int i = 0; i < TTY_p->Prototypes.size; ++i) {
if (nh_encoding_compareUTF32(((ttyr_tty_ProgramPrototype*)TTY_p->Prototypes.pp[i])->Name.p, Prototype_p->Name.p)) {
if (nh_encoding_compareUTF32(((ttyr_tty_Interface*)TTY_p->Prototypes.pp[i])->Name.p, Prototype_p->Name.p)) {
return TTYR_TTY_ERROR_BAD_STATE;
}
}
Expand All @@ -107,7 +107,7 @@ TTYR_TTY_RESULT ttyr_tty_addProgram(
ttyr_tty_Tile *Tile_p = Tiles.pp[i];
bool add = true;
for (int j = 0; TTYR_TTY_MACRO_TAB(Tile_p)->MicroWindow.Tabs_p && j < TTYR_TTY_MACRO_TAB(Tile_p)->MicroWindow.Tabs_p->size; ++j) {
ttyr_tty_ProgramPrototype *MicroTileProgramPrototype_p =
ttyr_tty_Interface *MicroTileProgramPrototype_p =
((ttyr_tty_MicroTab*)TTYR_TTY_MACRO_TAB(Tile_p)->MicroWindow.Tabs_p->pp[j])->Prototype_p;
if (!MicroTileProgramPrototype_p) {continue;}
if (nh_encoding_compareUTF32(MicroTileProgramPrototype_p->Name.p, Prototype_p->Name.p)) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/ttyr-tty/TTY/Program.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ typedef struct ttyr_tty_TTY ttyr_tty_TTY;
*/

TTYR_TTY_RESULT ttyr_tty_addProgram(
ttyr_tty_TTY *TTY_p, ttyr_tty_ProgramPrototype *Prototype_p, bool once
ttyr_tty_TTY *TTY_p, ttyr_tty_Interface *Prototype_p, bool once
);

ttyr_tty_Program *ttyr_tty_createProgramInstance(
ttyr_tty_ProgramPrototype *Prototype_p, bool once
ttyr_tty_Interface *Prototype_p, bool once
);

TTYR_TTY_RESULT ttyr_tty_destroyProgramInstance(
Expand Down
Loading

0 comments on commit 5f28a3b

Please sign in to comment.