This commit is contained in:
2020-06-01 19:14:01 -07:00
parent 87d2b360bb
commit 98e9bc5e70
15 changed files with 77 additions and 100 deletions

5
.gitignore vendored
View File

@@ -1,6 +1,7 @@
ncac
*.o
*.swp
*.swo
bazel-*
tags

12
BUILD
View File

@@ -1,12 +0,0 @@
cc_binary(
name = "ncac",
srcs = [
"ncac.cc",
"ncac.h",
],
deps = [
"//asana",
"//ui",
"@system_include//:curses"
],
)

4
Makefile Normal file
View File

@@ -0,0 +1,4 @@
CFLAGS=--std=c18 -O2 -Wall -Wextra -pedantic
LDLIBS=-lncurses -lcurl
ncac: ui/base.o asana/fetch.o ncac.o

View File

@@ -1,25 +0,0 @@
new_local_repository(
name = "system_include",
path = "/usr/lib",
build_file_content = """
cc_library(
name = "curses",
srcs = ["libcurses.dylib"],
visibility = ["//visibility:public"],
)
cc_library(
name = "curl",
srcs = ["libcurl.dylib"],
visibility = ["//visibility:public"],
)
""",
)
new_http_archive(
name = "gtest",
url = "https://github.com/google/googletest/archive/release-1.8.0.tar.gz",
sha256 = "58a6f4277ca2bc8565222b3bbd58a177609e9c488e8a72649359ba51450db7d8",
build_file = "gtest.BUILD",
strip_prefix = "googletest-release-1.8.0",
)

0
asana/asana.c Normal file
View File

4
asana/asana.h Normal file
View File

@@ -0,0 +1,4 @@
#ifndef ASANA_ASANA_H_
#define ASANA_ASANA_H_
#endif // ASANA_ASANA_H_

19
asana/fetch.c Normal file
View File

@@ -0,0 +1,19 @@
#include "fetch.h"
#include <stdbool.h>
#include <curl/curl.h>
CURL *curl;
bool asana_init() {
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if (!curl) return false;
return true;
}
void asana_cleanup() {
curl_global_cleanup();
}

16
asana/fetch.h Normal file
View File

@@ -0,0 +1,16 @@
#ifndef ASANA_FETCH_H_
#define ASANA_FETCH_H_
#include <stdbool.h>
/**
* initialize libcurl
*/
bool asana_init();
/**
* cleanup libcurl before program end
*/
void asana_cleanup();
#endif // ASANA_FETCH_H_

View File

@@ -1,13 +0,0 @@
cc_library(
name = "main",
srcs = glob(
["src/*.cc"],
exclude = ["src/gtest-all.cc"]
),
hdrs = glob([
"include/**/*.h",
"src/*.h"
]),
copts = ["-Iexternal/gtest/include"],
visibility = ["//visibility:public"],
)

1
ncac
View File

@@ -1 +0,0 @@
bazel-bin/ncac

BIN
ncac Executable file

Binary file not shown.

View File

@@ -2,10 +2,9 @@
#include <curses.h>
#include <stdlib.h>
#include <stdio.h>
#include <term.h>
#include <iostream>
#include "ui/base.h"
#include "asana/fetch.h"
@@ -21,10 +20,10 @@ int main(int argc, char **argv) {
while(1) {
switch (input = getch()) {
case 'a':
ui::draw_text("Hello, world!", &curs_x, &curs_y);
draw_text("Hello, world!", &curs_x, &curs_y);
break;
case 'b':
ui::draw_text("Goodbye, world!", &curs_x, &curs_y);
draw_text("Goodbye, world!", &curs_x, &curs_y);
break;
case 'q':
finish(SIGTERM);
@@ -36,26 +35,26 @@ int main(int argc, char **argv) {
static void finish(int sig) {
endwin();
asana::deinit();
asana_cleanup();
exit(0);
}
static void setup() {
// initialize the asana client
if (!asana::init()) {
std::cerr << "Unable to initialize the Asana client\n" << EOF;
if (!asana_init()) {
fprintf(stderr, "Unable to initialize the Asana client\n");
exit(1);
}
// initialize ncurses
if (!initscr()) {
std::cerr << "Unable to initialize the curses screen.\n" << EOF;
fprintf(stderr, "Unable to initialize the curses screen.\n");
exit(1);
}
// don't buffer or echo input
if (cbreak() == ERR) {
std::cerr << "Unable to initialize.\n" << EOF;
fprintf(stderr, "Unable to initialize.\n");
exit(1);
}
noecho();

View File

@@ -1,7 +0,0 @@
cc_library(
name="ui",
srcs = ["base.cc"],
hdrs = ["base.h"],
deps = ["@system_include//:curses"],
visibility = ["//visibility:public"],
)

18
ui/base.c Normal file
View File

@@ -0,0 +1,18 @@
#include "base.h"
#include <curses.h>
#include <string.h>
void draw_text(char *text, int *x, int *y) {
if (!text || strnlen(text, 1) == 0) return;
mvaddch(*y, *x, *text);
++text;
for (; *text != '\0'; ++text) {
addch(*text);
}
getyx(stdscr, *y, *x);
}

View File

@@ -1,23 +0,0 @@
#include "base.h"
#include <curses.h>
#include <string.h>
#include <string>
namespace ui {
void draw_text(const std::string text, int *x, int *y) {
if (!text.length()) return;
auto iter = text.begin();
mvaddch(*y, *x, *iter);
++iter;
for (; iter != text.end(); ++iter) {
addch(*iter);
}
getyx(stdscr, *y, *x);
}
}

View File

@@ -1,14 +1,10 @@
#ifndef UI_BASE_H_
#define UI_BASE_H_
#include <string>
/**
* Prints the string text starting at position *x, *y. x and y are updated to
* the position after the last character
*/
void draw_text(char *text, int *x, int *y);
namespace ui {
/**
* Prints the string text starting at position *x, *y. x and y are updated to
* the position after the last character
*/
void draw_text(const std::string text, int *x, int *y);
} // namespace ui
#endif // UI_BASE_H_