2024-05-04 18:04:00 +00:00
|
|
|
/*
|
2024-05-04 19:06:17 +00:00
|
|
|
* Copyright (C) 2024 - 2024:
|
2024-05-06 14:29:15 +00:00
|
|
|
* The Trinitrix Project <benedikt.peetz@b-peetz.de,
|
|
|
|
* antifallobst@systemausfall.org, sils@sils.li> SPDX-License-Identifier:
|
|
|
|
* GPL-3.0-or-later
|
2024-05-04 19:06:17 +00:00
|
|
|
*
|
|
|
|
* This file is part of Trinitrix.
|
|
|
|
*
|
2024-05-06 14:29:15 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
2024-05-04 19:06:17 +00:00
|
|
|
*
|
2024-05-06 14:29:15 +00:00
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
2024-05-04 19:06:17 +00:00
|
|
|
*
|
2024-05-06 14:29:15 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <https://www.gnu.org/licenses/>.
|
2024-05-04 19:06:17 +00:00
|
|
|
*/
|
2024-05-04 18:04:00 +00:00
|
|
|
|
|
|
|
#include "../../dist/interface.h"
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2024-05-04 19:06:17 +00:00
|
|
|
#define println(args...) \
|
|
|
|
fprintf (log_file, "\33[32;1m(plugin):\33[0m \33[34;1m"); \
|
|
|
|
fprintf (log_file, args); \
|
|
|
|
fprintf (log_file, "\n\33[0m"); \
|
|
|
|
fflush (log_file);
|
2024-05-04 18:04:00 +00:00
|
|
|
|
2024-05-04 19:06:17 +00:00
|
|
|
#define eprintln(args...) \
|
|
|
|
fprintf (log_file, "\33[32;1m(plugin):\33[0m\33[31;1m "); \
|
|
|
|
fprintf (log_file, args); \
|
|
|
|
fprintf (log_file, "\n\33[0m"); \
|
|
|
|
fflush (log_file);
|
2024-05-04 18:04:00 +00:00
|
|
|
|
|
|
|
int is_first_log_file_open = 1;
|
2024-05-04 19:06:17 +00:00
|
|
|
FILE *
|
|
|
|
get_log_file ()
|
|
|
|
{
|
2024-05-04 18:04:00 +00:00
|
|
|
FILE *log_file;
|
|
|
|
|
2024-05-04 19:06:17 +00:00
|
|
|
if (is_first_log_file_open)
|
|
|
|
{
|
|
|
|
is_first_log_file_open = 0;
|
|
|
|
log_file = fopen ("plugin.txt", "w");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log_file = fopen ("plugin.txt", "wa");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (log_file == NULL)
|
|
|
|
{
|
|
|
|
printf ("Error opening file!\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
2024-05-04 18:04:00 +00:00
|
|
|
|
|
|
|
return log_file;
|
|
|
|
}
|
|
|
|
|
2024-05-04 19:06:17 +00:00
|
|
|
void
|
|
|
|
handle_error ()
|
|
|
|
{
|
|
|
|
FILE *log_file = get_log_file ();
|
|
|
|
eprintln ("GOT an error");
|
|
|
|
|
|
|
|
int error_length = last_error_length ();
|
|
|
|
char *error = malloc (error_length);
|
|
|
|
last_error_message (error, error_length);
|
|
|
|
eprintln ("Encountered error: %s", error);
|
|
|
|
free (error);
|
2024-05-04 18:04:00 +00:00
|
|
|
}
|
|
|
|
|
2024-05-04 19:06:17 +00:00
|
|
|
void
|
|
|
|
set_normal_mode ()
|
|
|
|
{
|
|
|
|
if (!trinitrix.api.ui.set_mode (Normal))
|
|
|
|
handle_error ();
|
2024-05-04 18:04:00 +00:00
|
|
|
}
|
2024-05-04 19:06:17 +00:00
|
|
|
void
|
|
|
|
set_command_mode ()
|
|
|
|
{
|
|
|
|
if (!trinitrix.api.ui.set_mode (Command))
|
|
|
|
handle_error ();
|
2024-05-04 18:04:00 +00:00
|
|
|
}
|
2024-05-04 19:06:17 +00:00
|
|
|
void
|
|
|
|
set_insert_mode ()
|
|
|
|
{
|
|
|
|
if (!trinitrix.api.ui.set_mode (Insert))
|
|
|
|
handle_error ();
|
2024-05-04 18:04:00 +00:00
|
|
|
}
|
2024-05-04 19:06:17 +00:00
|
|
|
void
|
|
|
|
print_hi ()
|
|
|
|
{
|
|
|
|
if (!trinitrix.api.raw.raise_error ("hi!"))
|
|
|
|
handle_error ();
|
2024-05-04 18:04:00 +00:00
|
|
|
}
|
2024-05-04 19:06:17 +00:00
|
|
|
void
|
|
|
|
print_warning ()
|
|
|
|
{
|
|
|
|
if (!trinitrix.api.raw.raise_error (
|
2024-05-04 18:04:00 +00:00
|
|
|
"To exit trinitrix use 'trinitrix.api.exit()' instead!"))
|
2024-05-04 19:06:17 +00:00
|
|
|
handle_error ();
|
2024-05-04 18:04:00 +00:00
|
|
|
}
|
|
|
|
|
2024-05-04 19:06:17 +00:00
|
|
|
int
|
|
|
|
plugin_main ()
|
|
|
|
{
|
|
|
|
FILE *log_file = get_log_file ();
|
2024-05-04 18:04:00 +00:00
|
|
|
|
2024-05-04 19:06:17 +00:00
|
|
|
println ("Hi, setting first keymap!");
|
|
|
|
if (!trinitrix.api.keymaps.add ("ci", "<ESC>", set_normal_mode))
|
|
|
|
handle_error ();
|
|
|
|
println ("Done setting that keymap");
|
2024-05-04 18:04:00 +00:00
|
|
|
|
2024-05-04 19:06:17 +00:00
|
|
|
if (!trinitrix.api.keymaps.add ("n", ":", set_command_mode))
|
|
|
|
handle_error ();
|
2024-05-04 18:04:00 +00:00
|
|
|
|
2024-05-04 19:06:17 +00:00
|
|
|
trinitrix.api.keymaps.add ("n", "i", set_insert_mode);
|
|
|
|
trinitrix.api.keymaps.add ("n", "<TAB>", trinitrix.api.ui.cycle_planes);
|
2024-05-04 18:04:00 +00:00
|
|
|
|
|
|
|
// a simple test to prove that key chords work
|
2024-05-04 19:06:17 +00:00
|
|
|
trinitrix.api.keymaps.add ("ni", "jj", print_hi);
|
2024-05-04 18:04:00 +00:00
|
|
|
|
2024-05-04 19:06:17 +00:00
|
|
|
trinitrix.api.keymaps.add ("n", "q", trinitrix.api.exit);
|
2024-05-04 18:04:00 +00:00
|
|
|
|
|
|
|
// Help people
|
2024-05-04 19:06:17 +00:00
|
|
|
trinitrix.api.keymaps.add ("n", "<C-c>", print_warning);
|
2024-05-04 18:04:00 +00:00
|
|
|
|
|
|
|
// workaround to avoid c de-allocating our nice strings
|
2024-05-04 19:06:17 +00:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
};
|
2024-05-04 18:04:00 +00:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|