Skip to content

Commit

Permalink
Reorganize termbox source tree.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Jonas Young authored and nsf committed May 11, 2012
1 parent 9ef924d commit 749d67a
Show file tree
Hide file tree
Showing 25 changed files with 131 additions and 262 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Project: termbox - a ncurses alternative

May 5th 2012, youngkevinjonas@gmail.com:
I have completely reorganized the project
while leaving most of the code intact (fixed
a couple of warnings). Now you can either use
it as a dependency for a C/C++ project by employing
CMake, or you can install it as a Python package
by using Python distutils and Cython.

Fixed misuse of C prototypes (ie. foo() -> foo(void))
Changed a couple of include paths
53 changes: 24 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
#################################################################
# Termbox - A ncurses alternative
#
# Author: nsf - no.smile.face@gmail.com
# Website: http://code.google.com/p/termbox/
#
# Termbox library is a simple and clean ncurses alternative.
# Of course everything has it's own price.
# In this case it's portability and stability.
#
# Modified by: ykj - youngkevinjonas@gmail.com
# On: May 5th 2012
# I have completely reorganized the project
# while leaving most of the code intact (fixed
# a couple of warnings). Now you can either use
# it as a dependency for a C/C++ project by employing
# CMake, or you can install it as a Python package
# by using Python distutils and Cython.
#
# This file constitutes the CMake build.
#################################################################

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

PROJECT(TERMBOX C)

SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=gnu99")

SET(TERMBOX_LIB_SRC
${CMAKE_CURRENT_SOURCE_DIR}/input.c
${CMAKE_CURRENT_SOURCE_DIR}/ringbuffer.c
${CMAKE_CURRENT_SOURCE_DIR}/term.c
${CMAKE_CURRENT_SOURCE_DIR}/termbox.c
${CMAKE_CURRENT_SOURCE_DIR}/utf8.c
)

SET(KEYBOARD_SRC
${CMAKE_CURRENT_SOURCE_DIR}/keyboard.c
)


ADD_LIBRARY(termbox STATIC ${TERMBOX_LIB_SRC})
ADD_EXECUTABLE(keyboard ${KEYBOARD_SRC})
TARGET_LINK_LIBRARIES(keyboard termbox)

OPTION(TERMBOX_SHARED "Build static library for use in shared libraries (uses fPIC)" OFF)


IF(TERMBOX_SHARED)
SET_TARGET_PROPERTIES(termbox PROPERTIES COMPILE_FLAGS -fPIC)
ENDIF(TERMBOX_SHARED)

FIND_PROGRAM(PYREX pyrexc)
IF(PYREX)
SUBDIRS(py)
ENDIF()
ADD_SUBDIRECTORY(src)
28 changes: 28 additions & 0 deletions INSTALL
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Project: termbox - a ncurses alternative

This file describes how to build and install termbox,
depending on your usecase.

If you're a Python, run:
$ python setup.py install

Dependencies: Cython

And go ahead and use it as:
>>> import termbox
>>> (...)

If you would like to test termbox before installing:
$ python setup.py build_ext --inplace
$ python test_termboxmodule.py

(Press ESC to exit the program)

If you're more of a C/C++ dude, use:
$ mkdir build_termbox
$ cd build_termbox
$ cmake /path/to/src
$ make
$ (...)

Dependencies: cmake > 2.8
51 changes: 0 additions & 51 deletions Makefile

This file was deleted.

1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ It's general purpose to serve as the simplest ncurses alternative.

See NOTES for few important notes.
See WHEREWHAT to know where things are located.
See INSTALL for directions on building and installing termbox.
3 changes: 0 additions & 3 deletions compile.sh

This file was deleted.

12 changes: 0 additions & 12 deletions py/CMakeLists.txt

This file was deleted.

19 changes: 19 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

import glob

sourcefiles = ['src/termboxmodule.pyx'] + glob.glob('src/*.c')

setup(
name = 'termbox',
version = '1.0.1a1',
description = 'A simple and clean ncurses alternative',
author = 'nsf',
author_email = 'no.smile.face@gmail.com',
url = 'http://code.google.com/p/termbox/',
license = 'MIT',
cmdclass = {'build_ext': build_ext},
ext_modules = [Extension('termbox', sourcefiles)],
)
17 changes: 17 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
SET(TERMBOX_LIB_SRC
${CMAKE_CURRENT_SOURCE_DIR}/input.c
${CMAKE_CURRENT_SOURCE_DIR}/ringbuffer.c
${CMAKE_CURRENT_SOURCE_DIR}/term.c
${CMAKE_CURRENT_SOURCE_DIR}/termbox.c
${CMAKE_CURRENT_SOURCE_DIR}/utf8.c
)

ADD_LIBRARY(termbox STATIC ${TERMBOX_LIB_SRC})

OPTION(TERMBOX_SHARED "Build static library for use in shared libraries (uses fPIC)" OFF)

IF(TERMBOX_SHARED)
SET_TARGET_PROPERTIES(termbox PROPERTIES COMPILE_FLAGS -fPIC)
ENDIF(TERMBOX_SHARED)

ADD_SUBDIRECTORY(demo)
6 changes: 6 additions & 0 deletions src/demo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SET(KEYBOARD_SRC
${CMAKE_CURRENT_SOURCE_DIR}/keyboard.c
)

ADD_EXECUTABLE(keyboard ${KEYBOARD_SRC})
TARGET_LINK_LIBRARIES(keyboard termbox)
2 changes: 1 addition & 1 deletion keyboard.c → src/demo/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <stdint.h>
#include <stdarg.h>
#include <stdio.h>
#include "termbox.h"
#include "../termbox.h"

struct key {
unsigned char x;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion term.c → src/term.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static int try_compatible(const char *term, const char *name,
return EUNSUPPORTED_TERM;
}

int init_term()
int init_term(void)
{
int i;
const char *term = getenv("TERM");
Expand Down
2 changes: 1 addition & 1 deletion term.h → src/term.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum {

#define EUNSUPPORTED_TERM -1

int init_term();
int init_term(void);

/* 0 on success, -1 on failure */
int extract_event(struct tb_event *event, struct ringbuffer *inbuf, int inputmode);
Expand Down
24 changes: 12 additions & 12 deletions termbox.c → src/termbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ static void cellbuf_resize(struct cellbuf *buf, unsigned int width, unsigned int
static void cellbuf_clear(struct cellbuf *buf);
static void cellbuf_free(struct cellbuf *buf);

static void update_size();
static void update_term_size();
static void update_size(void);
static void update_term_size(void);
static void send_attr(uint16_t fg, uint16_t bg);
static void send_char(unsigned int x, unsigned int y, uint32_t c);
static void send_clear();
static void send_clear(void);
static void sigwinch_handler(int xxx);
static int wait_fill_event(struct tb_event *event, struct timeval *timeout);

Expand All @@ -69,7 +69,7 @@ static volatile int buffer_size_change_request;

/* -------------------------------------------------------- */

int tb_init()
int tb_init(void)
{
out = fopen("/dev/tty", "w");
in = fopen("/dev/tty", "r");
Expand Down Expand Up @@ -121,7 +121,7 @@ int tb_init()
return 0;
}

void tb_shutdown()
void tb_shutdown(void)
{
fputs(funcs[T_SHOW_CURSOR], out);
fputs(funcs[T_SGR0], out);
Expand All @@ -141,7 +141,7 @@ void tb_shutdown()
free_ringbuffer(&inbuf);
}

void tb_present()
void tb_present(void)
{
unsigned int x,y;
struct tb_cell *back, *front;
Expand Down Expand Up @@ -227,17 +227,17 @@ int tb_peek_event(struct tb_event *event, unsigned int timeout)
return wait_fill_event(event, &tv);
}

unsigned int tb_width()
unsigned int tb_width(void)
{
return termw;
}

unsigned int tb_height()
unsigned int tb_height(void)
{
return termh;
}

void tb_clear()
void tb_clear(void)
{
if (buffer_size_change_request) {
update_size();
Expand Down Expand Up @@ -322,7 +322,7 @@ static void get_term_size(int *w, int *h)
if (h) *h = sz.ws_row;
}

static void update_term_size()
static void update_term_size(void)
{
struct winsize sz;
memset(&sz, 0, sizeof(sz));
Expand Down Expand Up @@ -364,7 +364,7 @@ static void send_char(unsigned int x, unsigned int y, uint32_t c)
fputs(buf, out);
}

static void send_clear()
static void send_clear(void)
{
send_attr(foreground, background);
fputs(funcs[T_CLEAR_SCREEN], out);
Expand All @@ -387,7 +387,7 @@ static void sigwinch_handler(int xxx)
write(winch_fds[1], &zzz, sizeof(int));
}

static void update_size()
static void update_size(void)
{
update_term_size();
cellbuf_resize(&back_buffer, termw, termh);
Expand Down
12 changes: 6 additions & 6 deletions termbox.h → src/termbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ struct tb_event {
#define TB_EFAILED_TO_OPEN_TTY -2
#define TB_EPIPE_TRAP_ERROR -3

SO_IMPORT int tb_init();
SO_IMPORT void tb_shutdown();
SO_IMPORT int tb_init(void);
SO_IMPORT void tb_shutdown(void);

SO_IMPORT unsigned int tb_width();
SO_IMPORT unsigned int tb_height();
SO_IMPORT unsigned int tb_width(void);
SO_IMPORT unsigned int tb_height(void);

SO_IMPORT void tb_clear();
SO_IMPORT void tb_present();
SO_IMPORT void tb_clear(void);
SO_IMPORT void tb_present(void);

#define TB_HIDE_CURSOR -1
SO_IMPORT void tb_set_cursor(int cx, int cy);
Expand Down
2 changes: 1 addition & 1 deletion py/termbox.pyx → src/termboxmodule.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ cdef extern from "stdint.h":
ctypedef unsigned short uint16_t
ctypedef signed int int32_t

cdef extern from "../termbox.h":
cdef extern from "termbox.h":
struct tb_event:
uint16_t type
uint32_t ch
Expand Down
File renamed without changes.
Loading

0 comments on commit 749d67a

Please sign in to comment.