include doszip/doszip.inc
include string.inc
include	conio.inc
include	cursor.inc
include	tinfo.inc
include	keyb.inc

	public	com_base
	public	com_wsub
	public	com_info

_DATA	SEGMENT

com_push db 1
com_base db 0
	 db WMAXPATH-1 dup(?)
com_info S_TINFO <DGROUP:com_base, _T_OVERWRITE, 0, 24, 80, \
	 WMAXPATH, 0, 0, 07h, ' ', 06071900h, 0>
com_wsub dw offset wspanela
	 dw SEG _DATA

_DATA	ENDS

_DZIP	SEGMENT

comhndlevent proc public
	.if cflag & _C_COMMANDLINE
	    push offset com_info
	    push ax
	    call cursoron
	    call tihndlevent
	.else
	    xor ax,ax
	.endif
	ret
comhndlevent endp

comevent proc pascal public uses si event:word
	mov dx,event
	mov si,1
	mov ax,dx
	.if ax == KEY_UP
	    call cpanel_state
	    .if	!ZERO?
		dec si
	    .else
		call cmdoskey_up
	    .endif
	.elseif ax == KEY_DOWN
	    call cpanel_state
	    .if	!ZERO?
		dec si
	    .else
		call cmdoskey_dn
	    .endif
	.elseif ax == KEY_RIGHT
	    .if	com_base && dx
		jmp @F
	    .endif
	.elseif ax == KEY_ALTRIGHT
	     call cmpathright
	.elseif ax == KEY_ALTLEFT
	     call cmpathleft
	.else
    @@:
	     .if dx
		 mov ax,dx
		 invoke comhndlevent
		 .if ax
		     dec si
		 .endif
	     .endif
	.endif
	mov	ax,si
	ret
comevent endp

comhide	proc public
	invoke	dlhide, DLG_Commandline
	call	cursoroff
	mov	com_base,0
	ret
comhide	endp

comshow	proc public
	mov ax,com_info.ti_ypos
	xor bx,bx
	.if byte ptr prect_b & _D_ONSCR
	    mov bx,offset prect_b
	.elseif byte ptr prect_a & _D_ONSCR
	    mov bx,offset prect_a
	.endif
	.if bx
	    mov dl,[bx].dl_rect.rc_y
	    add dl,[bx].dl_rect.rc_row
	    .if dl > al
		mov al,dl
	    .endif
	.endif
	.if !al && cflag & _C_MENUSLINE
	    inc al
	.endif
	.if al >= _scrrow && cflag & _C_STATUSLINE
	    dec al
	.endif
	.if al > _scrrow
	    mov al,_scrrow
	.endif
	mov byte ptr com_info.ti_ypos,al
	les bx,DLG_Commandline
	mov es:[bx+5],al
	invoke gotoxy, 0, ax
	.if cflag & _C_COMMANDLINE
	    call cursoron
	    invoke dlshow, DLG_Commandline
	    call cominitline
	.endif
	ret
comshow	endp

cominitline proc
	les bx,DLG_Commandline
	.if byte ptr es:[bx] & _D_ONSCR
	    mov	ax,es:[bx+4]
	    mov	com_info.ti_cursor.cr_xy,ax
	    mov	byte ptr com_info.ti_ypos,ah
	    mov	byte ptr com_info.ti_xpos,al
	    mov	bx,com_wsub
	    invoke strlen, [bx.ws_path]
	    inc	ax
	    .if	ax > 51
		mov ax,51
	    .endif
	    mov	com_info.ti_xpos,ax
	    mov	dl,80
	    sub	dl,al
	    mov	byte ptr com_info.ti_cols,dl
	    scputw@ 0, byte ptr com_info.ti_ypos, 80, ' '
	    mov	bx,com_wsub
	    lodm [bx.ws_path]
	    scpath@ 0, byte ptr com_info.ti_cursor.cr_xy+1, 50, dx, ax
	    mov	bl,byte ptr com_info.ti_xpos
	    dec	bl
	    scputw@ bl, bh, 1, 62 ; '>'
	    inc	bl
	    mov	al,bh
	    invoke gotoxy, bx, ax
	    mov	ax,KEY_PGUP
	    call comhndlevent
	.endif
	ret
cominitline endp

cominit	proc pascal public wsub:dword
	movmm	com_wsub,wsub
	invoke	wsinit, dx::ax
	call	cominitline
	mov	ax,1
	ret
cominit	endp

clrcmdl	proc dist public
	mov	com_base,0
	call	cominitline
	invoke	comevent, KEY_HOME
	ret
clrcmdl	endp

cmclrcmdl proc dist public
	.if cflag & _C_ESCUSERSCR
	    call cmtoggleon
	.else
	    call clrcmdl
	.endif
	ret
cmclrcmdl endp

_DZIP	ENDS

	END
