Commit 2d7f7d45 authored by Ticki's avatar Ticki

Add LICENSE, remove ANSI stuff in favor of libterm

parent f46a2a31
The MIT License (MIT)
Copyright (c) 2016 Ticki
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
......@@ -7,154 +7,6 @@ use buffer::Buffer;
#[cfg(feature = "orbital")]
use orbclient::Color;
#[cfg(feature = "ansi")]
mod terminal {
extern crate libc;
use std::mem;
use self::libc::{c_int, c_uint, c_ushort, c_uchar, STDOUT_FILENO};
use self::libc::ioctl;
use std::io::stdout;
use std::io::prelude::*;
extern {
static tiocgwinsz: c_int;
fn tcgetattr(filedes: c_int, termptr: *mut Termios) -> c_int;
fn tcsetattr(filedes: c_int, opt: c_int, termptr: *mut Termios) -> c_int;
fn cfmakeraw(termptr: *mut Termios);
}
#[repr(C)]
struct TermSize {
row: c_ushort,
col: c_ushort,
_x: c_ushort,
_y: c_ushort,
}
pub fn termsize() -> Option<(usize, usize)> {
unsafe {
let mut size: TermSize = mem::zeroed();
if ioctl(STDOUT_FILENO, tiocgwinsz as u64, &mut size as *mut _) == 0 {
Some((size.col as usize, size.row as usize))
} else {
None
}
}
}
#[derive(Clone)]
struct Termios {
c_iflag: c_uint,
c_oflag: c_uint,
c_cflag: c_uint,
c_lflag: c_uint,
c_line: c_uchar,
c_cc: [c_uchar; 32],
c_ispeed: c_uint,
c_ospeed: c_uint,
}
fn get_terminal_attr() -> (Termios, c_int) {
unsafe {
let mut ios = Termios {
c_iflag: 0,
c_oflag: 0,
c_cflag: 0,
c_lflag: 0,
c_line: 0,
c_cc: [0; 32],
c_ispeed: 0,
c_ospeed: 0
};
(ios, tcgetattr(0, &mut ios))
}
}
fn make_raw(ios: &mut Termios) {
unsafe {
cfmakeraw(&mut *ios);
}
}
fn set_terminal_attr(ios: *mut Termios) -> c_int {
unsafe {
tcsetattr(0, 0, ios)
}
}
pub struct TerminalRestorer {
prev_ios: Termios
}
impl Drop for TerminalRestorer {
fn drop(&mut self) {
set_terminal_attr(&mut self.prev_ios as *mut _);
}
}
pub fn set_terminal_raw_mode() -> TerminalRestorer {
let (ios, err) = get_terminal_attr();
let prev_ios = ios.clone();
if err != 0 {
panic!("Can't load termios settings properly");
}
make_raw(&mut ios);
if set_terminal_attr(&mut ios as *mut _) != 0 {
panic!("Can't init termios raw mode properly");
}
TerminalRestorer {
prev_ios: prev_ios,
}
}
pub fn csi(b: &[u8]) {
let stdout = stdout();
stdout.write(b"\x1B[");
stdout.write(b);
stdout.flush();
}
pub fn print(b: &[u8]) {
let stdout = stdout();
stdout.write(b);
stdout.flush();
}
pub fn clear() {
csi(b"2J");
}
pub fn show_cursor() {
csi(b"?25h");
}
pub fn hide_cursor() {
csi(b"?25l");
}
pub fn reset_style() {
csi(b"0m");
}
pub fn move_cursor(x: usize, y: usize) {
csi(&[]);
print(y.to_string().as_bytes());
print(b";");
print(x.to_string().as_bytes());
print(b"H");
}
}
#[cfg(feature = "orbital")]
impl Editor {
/// Redraw the window
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment