enhanced the main program to show prompt in the interactive mode
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
26
lib/fmt.c
26
lib/fmt.c
@ -1696,6 +1696,18 @@ hcl_ooi_t hcl_logbfmtv (hcl_t* hcl, hcl_bitmask_t mask, const hcl_bch_t* fmt, va
|
||||
mask |= HCL_LOG_UNTYPED;
|
||||
}
|
||||
|
||||
if (!fmt)
|
||||
{
|
||||
/* perform flushing only if fmt is NULL */
|
||||
if (hcl->log.len > 0)
|
||||
{
|
||||
HCL_VMPRIM_LOG_WRITE (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len);
|
||||
hcl->log.len = 0;
|
||||
}
|
||||
HCL_VMPRIM_LOG_WRITE (hcl, hcl->log.last_mask, HCL_NULL, 0); /* forced flushing */
|
||||
return 0;
|
||||
}
|
||||
|
||||
HCL_MEMSET (&fo, 0, HCL_SIZEOF(fo));
|
||||
fo.fmt_type = HCL_FMTOUT_FMT_TYPE_BCH;
|
||||
fo.fmt_str = fmt;
|
||||
@ -1751,6 +1763,19 @@ hcl_ooi_t hcl_logufmtv (hcl_t* hcl, hcl_bitmask_t mask, const hcl_uch_t* fmt, va
|
||||
mask |= HCL_LOG_UNTYPED;
|
||||
}
|
||||
|
||||
|
||||
if (!fmt)
|
||||
{
|
||||
/* perform flushing only if fmt is NULL */
|
||||
if (hcl->log.len > 0)
|
||||
{
|
||||
HCL_VMPRIM_LOG_WRITE (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len);
|
||||
hcl->log.len = 0;
|
||||
}
|
||||
HCL_VMPRIM_LOG_WRITE (hcl, hcl->log.last_mask, HCL_NULL, 0); /* forced flushing */
|
||||
return 0;
|
||||
}
|
||||
|
||||
HCL_MEMSET (&fo, 0, HCL_SIZEOF(fo));
|
||||
fo.fmt_type = HCL_FMTOUT_FMT_TYPE_UCH;
|
||||
fo.fmt_str = fmt;
|
||||
@ -1768,6 +1793,7 @@ hcl_ooi_t hcl_logufmtv (hcl_t* hcl, hcl_bitmask_t mask, const hcl_uch_t* fmt, va
|
||||
HCL_VMPRIM_LOG_WRITE (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len);
|
||||
hcl->log.len = 0;
|
||||
}
|
||||
|
||||
return (x <= -1)? -1: fo.count;
|
||||
}
|
||||
|
||||
|
14
lib/std.c
14
lib/std.c
@ -534,10 +534,10 @@ static int write_log (hcl_t* hcl, int fd, const hcl_bch_t* ptr, hcl_oow_t len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void flush_log (hcl_t* hcl, int fd)
|
||||
static void flush_log (hcl_t* hcl, int fd, int force)
|
||||
{
|
||||
xtn_t* xtn = GET_XTN(hcl);
|
||||
if (xtn->log.out.len > 0)
|
||||
if (xtn->log.out.len > 0 || force)
|
||||
{
|
||||
write_all (fd, xtn->log.out.buf, xtn->log.out.len);
|
||||
xtn->log.out.len = 0;
|
||||
@ -551,6 +551,7 @@ static void log_write (hcl_t* hcl, hcl_bitmask_t mask, const hcl_ooch_t* msg, hc
|
||||
|
||||
xtn_t* xtn = GET_XTN(hcl);
|
||||
int logfd;
|
||||
int force_flush = 0;
|
||||
|
||||
if (mask & HCL_LOG_STDERR) logfd = 2;
|
||||
else if (mask & HCL_LOG_STDOUT) logfd = 1;
|
||||
@ -627,6 +628,12 @@ static void log_write (hcl_t* hcl, hcl_bitmask_t mask, const hcl_ooch_t* msg, hc
|
||||
else if (mask & HCL_LOG_WARN) write_log (hcl, logfd, "\x1B[1;33m", 7);
|
||||
}
|
||||
|
||||
if (!msg)
|
||||
{
|
||||
force_flush = 1;
|
||||
goto flush_log_msg;
|
||||
}
|
||||
|
||||
#if defined(HCL_OOCH_IS_UCH)
|
||||
msgidx = 0;
|
||||
while (len > 0)
|
||||
@ -673,7 +680,8 @@ static void log_write (hcl_t* hcl, hcl_bitmask_t mask, const hcl_ooch_t* msg, hc
|
||||
if (mask & (HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN)) write_log (hcl, logfd, "\x1B[0m", 4);
|
||||
}
|
||||
|
||||
flush_log (hcl, logfd);
|
||||
flush_log_msg:
|
||||
flush_log (hcl, logfd, force_flush);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user