From 0a53c7f17b09fa1eaf38d0948a3be1309bb0711a Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Fri, 29 Jan 2016 03:25:50 +0100 Subject: [PATCH] improve sys --- edit/writer.go | 3 +-- sys/godef | 3 --- sys/ioctl.go | 1 - sys/winsize.go | 24 +++++++++++------------- sys/z-winsize.go | 22 ---------------------- 5 files changed, 12 insertions(+), 41 deletions(-) delete mode 100755 sys/godef delete mode 100644 sys/z-winsize.go diff --git a/edit/writer.go b/edit/writer.go index 50ceadaa..d34cd631 100644 --- a/edit/writer.go +++ b/edit/writer.go @@ -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 diff --git a/sys/godef b/sys/godef deleted file mode 100755 index f2c00dc9..00000000 --- a/sys/godef +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -echo godef >> /tmp/xiaq -go tool cgo -godefs "$1" > "$2" diff --git a/sys/ioctl.go b/sys/ioctl.go index 175f686e..7417fedc 100644 --- a/sys/ioctl.go +++ b/sys/ioctl.go @@ -1,6 +1,5 @@ package sys -import "C" import ( "os" "syscall" diff --git a/sys/winsize.go b/sys/winsize.go index ed5e3b88..94bb9dc4 100644 --- a/sys/winsize.go +++ b/sys/winsize.go @@ -1,24 +1,22 @@ -// +build generate - package sys /* #include #include + +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) } diff --git a/sys/z-winsize.go b/sys/z-winsize.go deleted file mode 100644 index 983a619f..00000000 --- a/sys/z-winsize.go +++ /dev/null @@ -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 -}