improve sys

This commit is contained in:
Qi Xiao 2016-01-29 03:25:50 +01:00
parent e70c214c6a
commit 0a53c7f17b
5 changed files with 12 additions and 41 deletions

View File

@ -330,8 +330,7 @@ func renderNavColumn(nc *navColumn, w, h int) *buffer {
// refresh redraws the line editor. The dot is passed as an index into text;
// the corresponding position will be calculated.
func (w *writer) refresh(es *editorState) error {
winsize := sys.GetWinsize(int(w.file.Fd()))
width, height := int(winsize.Col), int(winsize.Row)
height, width := sys.GetWinsize(int(w.file.Fd()))
var bufLine, bufMode, bufTips, bufListing, buf *buffer
// bufLine

View File

@ -1,3 +0,0 @@
#!/bin/sh
echo godef >> /tmp/xiaq
go tool cgo -godefs "$1" > "$2"

View File

@ -1,6 +1,5 @@
package sys
import "C"
import (
"os"
"syscall"

View File

@ -1,24 +1,22 @@
// +build generate
package sys
/*
#include <termios.h>
#include <sys/ioctl.h>
void getwinsize(int fd, int *row, int *col) {
struct winsize wsz;
ioctl(fd, TIOCGWINSZ, &wsz);
*row = wsz.ws_row;
*col = wsz.ws_col;
}
*/
import "C"
import (
"syscall"
"unsafe"
)
// Winsize wraps the C winsize struct and represents the size of a terminal.
type Winsize C.struct_winsize
// GetWinsize queries the size of the terminal referenced by the given file
// descriptor.
func GetWinsize(fd int) Winsize {
var ws Winsize
Ioctl(fd, syscall.TIOCGWINSZ, uintptr(unsafe.Pointer(&ws)))
return ws
func GetWinsize(fd int) (row, col int) {
var r, c C.int
C.getwinsize(C.int(fd), &r, &c)
return int(r), int(c)
}

View File

@ -1,22 +0,0 @@
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs winsize.go
package sys
import (
"syscall"
"unsafe"
)
type Winsize struct {
Row uint16
Col uint16
Xpixel uint16
Ypixel uint16
}
func GetWinsize(fd int) Winsize {
var ws Winsize
Ioctl(fd, syscall.TIOCGWINSZ, uintptr(unsafe.Pointer(&ws)))
return ws
}